Open In App

How to align Image in HTML?

Last Updated : 29 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Aligning images within a webpage is an essential part of web design. It allows you to control how images are positioned about surrounding content. In HTML, there are several ways to align images using both attributes and CSS techniques, ranging from simple alignment to more advanced responsive layouts.

Syntax

To align an image using the align attribute, the syntax is as follows:

<img align="left|right|middle|top|bottom">

Attribute Values

  • left: Aligns the image to the left.
  • right: Aligns the image to the right.
  • middle: Aligns the image to the middle.
  • top: Aligns the image to the top.
  • bottom: Aligns the image to the bottom.

Methods for Aligning Images in HTML

Below are the common methods for aligning images in HTML:

1. Left Alignment of the Image

Left alignment places the image on the left side of its container, and surrounding text or other elements will flow around it on the right side. It is also used when we want the image to appear alongside the text.

Syntax

<img align="left">
  • align=”left”: Aligns the image to the left of its container. The surrounding content, such as text, will flow around it on the right.

Now, let us understand with the help of the example:

HTML
<html>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Welcome to GeeksforGeeks</h3>
    <h4>Left Alignment of Image</h4>
    <!-- Keep align attribute value as left -->
    <img align="left" 
         src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png" 
         alt="">
</body>
</html>

 Output: 

2. Right Alignment of the Image

Right alignment of an image places it on the right side of its container. This allows the text to wrap around it on the left, which can be used to balance the layout visually or create a specific flow of content.

Syntax

<img align="right"> 
  • align=”right”: Aligns the image to the right side of its container. Text or other content flows around it on the left, which can be visually appealing when you want to balance text and image alignment within the page.

Now, let us understand with the help of the example:

HTML
<html>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Welcome to GeeksforGeeks</h3>
    <h4>Right Alignment of Image</h4>
    <!-- Keep align attribute value as right -->
    <img align="right" 
         src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png" 
         alt="">
</body>
</html>

 Output

3. Middle Alignment of the Image 

Middle alignment centers the image vertically in relation to the surrounding text. This creates a balanced visual effect, especially when the image and text are inline or when you want to align the image with the middle of a block of text.

Syntax

<img align="middle">

Now, let us understand with the help of the example:

HTML
<html>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Welcome to GeeksforGeeks</h3>
    <h4>Middle Alignment of Image</h4>
    <!-- Keep align attribute value as "middle" -->
    <h4>GeeksforGeeks
        <img align="middle" 
             src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png"
             alt="">
        GeeksforGeeks
    </h4>
</body>
</html>

 Output

4. Top Alignment of the Image

Top alignment places the image at the top relative to the surrounding text. This method ensures that the image’s top edge aligns with the top of the text block, creating a clean and consistent start point for the content.

Syntax

<img align="top">

Now, let us understand with the help of the example:

HTML
<html>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Welcome to GeeksforGeeks</h3>
    <h4>Top Alignment of Image</h4>
    <!-- Keep align attribute value as "top" -->
    <h4>GeeksforGeeks
        <img align="top" 
             src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png" 
             alt="">
        GeeksforGeeks
    </h4>
</body>
</html>

 Output

5. Bottom Alignment of the Image

Bottom alignment positions the image at the bottom of the container, ensuring the top of the text aligns with the top of the image. This creates a baseline alignment effect, making the image appear to anchor the text.

Syntax

<img align="bottom">

Now, let us understand with the help of the example:

HTML
<html>
<body>
    <h1>GeeksforGeeks</h1>
    <h3>Welcome to GeeksforGeeks</h3>
    <h4>Bottom Alignment of Image</h4>
    <!-- Keep align attribute value as "bottom" -->
    <h4>GeeksforGeeks
        <img align="bottom" 
             src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png" 
             alt="">
        GeeksforGeeks
    </h4>
</body>
</html>

 Output:

Note => Using the align attribute in the <img> tag allows for easy alignment of images within your web pages. While this method is straightforward, it is recommended to use CSS for more flexibility and modern web design practices.

Conclusion

Aligning images in HTML is an essential part of web design, and there are multiple ways to achieve the desired layout. The align attribute offers quick and simple alignment options, but for modern, responsive web design, CSS techniques like Flexbox, Grid, and CSS float provide greater control and flexibility.



Next Article

Similar Reads