Text alignment with the align attribute

The normal text alignment depends on how the text is read in the browser's default language. If the text is read, for instance, from left to right, the normal alignment is left. On the other hand, if the text is read from right to left, the normal alignment is right.

If you want to change the normal alignment of the text, you can use the align attribute. With the attribute, you could use one of these values:

  1. left
  2. right
  3. center
  4. justify

Left alignment

To align text to the left margin, set the align attribute to left:

<p align="left">This paragraph uses the left alignment. If a language is read from left to right and the browser is set to that language, the default alignment is left. When the text is aligned automatically to the left, use of the align attribute with the value left is not necessary.</p>

Output of the above code:

This paragraph uses the left alignment. If a language is read from left to right and the browser is set to that language, the default alignment is left. When the text is aligned automatically to the left, use of the align attribute with the value left is not necessary.

Right alignment

To align text the right margin, set the align attribute to right:

<p align="right">This paragraph uses the right alignment. If a browser's default language is read from right to left, the default alignment is right. When the text is aligned automatically to the right, use of the align attribute with the value right is not necessary.</p>

Output of the above code:

This paragraph uses the right alignment. If a browser's default language is read from right to left, the default alignment is right. When the text is aligned automatically to the right, use of the align attribute with the value right is not necessary.

Center alignment

To change the alignment of the text to the center of the page, set the align attribute to center:

<p align="center">This paragraph uses the center alignment. Aligning text center is easy: simply set the align attribute to center or use the <center> tag.</p>

Output of the above code:

This paragraph uses the center alignment. Aligning text center is easy: simply set the align attribute to center or use the <center> tag.

Justified alignment

When you want to continue the text to the right and left margins, set the align attribute to justify:

<p align="justify">This paragraph uses the justify alignment. The paragraph is justified: the text continues to both margins.</p>

Output of the above code:

This paragraph uses the justify alignment. The paragraph is justified: the text continues to both margins.