Learn web page formatting and how to align text and objects around images using the align attribute of the HTML img tag.

Sponsored Links

Aligning text and objects around images

The align attribute of <img> tag helps in aligning other elements like text with respect to the image. It can take any of the following values:

  • top: Aligns the image to the top of adjoining object.
  • middle: Aligns the text baseline to the middle of the image.
  • bottom: Text baseline is aligned to the bottom of the image. This is the default value.
  • left & right: Image is aligned right of left with text wrapping around it.
  • absmiddle, absbottom and baseline: Aligns the image with respect to the middle, bottom or baseline of the text.
  • texttop: Aligns the image top with respect to the ascenders of the text. This attribute value is Netscape specific.
  • center: works same as align="middle".

However, a situation might arise when you would like to place only some text, say, a small description, on the left or right side of the image with the rest to flow after the image.

In our example, we want to align "What a fine idea!" to the left of the image with other sentences to be placed after the image.

If you use the following code, you shall not get the desired results.

<img src="bulb.gif" width="128" height="220" alt="Fine idea" 
align="right">
What a fine idea!<br>The bulb in this ...

Fine idea!What a fine idea!
The bulb in this image represents an idea that I have cherished over the months but did not get time to implement.

You'll notice that the next line - "The Bulb in this ..." - also lies to the left of the image, while we wanted to place it below the image.

To force the next line to place below the image, we use clear attribute of <br> tag with "all" as value. Thus, placing <br clear="all"> right after the phrase will force the next line to start at a new line.

<img src="bulb.gif" width="128" height="220" alt="Fine idea" 
align="right"><
What a fine idea!<br clear="all">The bulb in this ...

Fine idea!What a fine idea!
The bulb in this image represents an idea that I have cherished over the months but did not get time to implement.

Page contents: Understanding web page formatting and how to align text and other objects on a web page around images using the ALIGN attribute of the HTML <IMG> tag.

AddThis Social Bookmark Button

Recent Articles