Open In App

How to Align Text in HTML?

Last Updated : 23 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In earlier versions of HTML, the align attribute was commonly used to align text to the left, right, or center. However, this attribute is now deprecated in HTML5 and should no longer be used in modern web development.

Instead, text alignment is handled more effectively using CSS with the text-align property, which offers greater flexibility and cleaner code. According to modern web standards, over 95% of professional websites now rely on CSS for styling, including text alignment, making it the preferred approach for consistent and responsive design.

Method 1. Align Text using the "align attribute" [deprecated]

The align attribute is used to specify the text alignment within paragraph tags and set the text position to left, center, or right.

index.html
<p align="left">
    This text is left-aligned using the align attribute.
</p>
<p align="center">
    This text is center-aligned using the align attribute.
</p>
<p align="right">
    This text is right-aligned using the align attribute.
</p>

Output

textAlign
align text using align attribute

Method 2. Align text using "CSS text-align Property" [Recommended]

The text-align property is used to set the horizontal alignment of text within an element. It applies to block-level elements and aligns the inline content accordingly.

index.html
<!DOCTYPE html>
<html>
<head>
    <style>
        .left-align {
            text-align: left;
        }
        .center-align {
            text-align: center;
        }
        .right-align {
            text-align: right;
        }
    </style>
</head>
<body>
    <p class="left-align">
      This text is left-aligned using the text-align property.
  	</p>
    <p class="center-align">
      This text is center-aligned using the text-align property.
  	</p>
    <p class="right-align">
      This text is right-aligned using the text-align property.
  	</p>
</body>
</html>

Output

textAlignProperty
text align property

How to Align Text in HTML?

Similar Reads