How to align images in HTML

To move an image on our web pages to a different location (the top, bottom, right, left, or middle), use image alignment. To align the image, we utilize the <IMG> align attribute.

  • LEFT: It’s employed to align images to the left.
  • RIGHT: The image is aligned to the right using this.
  • MIDDLE: This is used to align an image with the center.
  • TOP: It’s utilized to align images with the top.
  • BOTTOM: The image is aligned to the bottom using this.

Use the attribute value "left" to align the image to the left. Use the attribute value "right" to align the image to the right. Use the attribute value "middle" to align the image to the center.

Now let’s look at how to align an image using HTML and CSS.

The CSS text-align property can be used to center an image horizontally. Using the text-align, margin, and flex properties are the three methods available for centering an image horizontally. Using a block element such as a div and a combination of the CSS position, left, and top properties along with the transform property, you can center an image vertically. You can use the flex property to center images vertically, just like we did previously when we centered the image horizontally. With Bootstrap CSS, you can center an image both horizontally and vertically by giving it the mx-auto class and enclosing it in a div element with the align-items-center and d-flex classes.

The next thing we’ll cover in HTML is how to align an image anywhere.

  • CENTER ALIGNMENT OF IMAGE IN HTML USING CSS (HORIZONTALLY CENTER): To center the image, turn it into a block element and set the left and right margins to auto.
  • MIDDLE ALIGNMENT (CENTER VERTICALLY): Decide on the middle vertical alignment.
  • Higher Alignment: Assign text-top to the vertical alignment.

The next topic is HTML image alignment without CSS.

  • We can center it by using the style attribute’s text-align property.
  • By transforming our image into a block-level element, we can align it.
  • To align a specific image, we can use the <center> tag.
  • We can make use of CSS FLEXBOX.
  • Additionally, we can make use of CSS GRID.