Last Updated : 23 Jul, 2025
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.
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
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
text align propertyHow to Align Text in HTML?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4