Last Updated : 12 Jul, 2025
The HTML <th> align Attribute is used to set the horizontal alignment of text content inside the table header cell. Instead, use CSS for alignment properties such as text-align
to specify the horizontal alignment and vertical-align
for vertical alignment within table headers.
Syntax:Note: The align attribute is not supported by HTML5.
<th align= "left | right | center | justify | char">Attribute Values:
Attribute Values
Description
left
It sets the text left-aligned.
right
It sets the text right-align.
center
It sets the text center-align.
justify
It stretches the text of paragraph to set the width of all lines equal.
char
It sets the text-align to a specific character.
Example: The implementation of the align attribute
html
<!DOCTYPE html>
<html>
<head>
<title>
HTML th align Attribute
</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML th align Attribute</h2>
<table width="300" border="1">
<tr>
<th align="left">NAME</th>
<th align="center">AGE</th>
<th align="right">BRANCH</th>
</tr>
<tr>
<td>BITTU</td>
<td>22</td>
<td>CSE</td>
</tr>
<tr>
<td>RAKESH</td>
<td>25</td>
<td>EC</td>
</tr>
</table>
</body>
</html>
Output:
Using CSS Instead of the align AttributeIn modern HTML5, it's recommended to use CSS to manage text alignment in table headers. The text-align property can handle horizontal alignment, while the vertical-align property controls vertical alignment.
Example: Here’s how you can replace the deprecated align attribute with CSS:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Modern CSS Alignment Example</title>
<style>
/* CSS for table header alignment */
th.left-align {
text-align: left;
}
th.center-align {
text-align: center;
}
th.right-align {
text-align: right;
}
</style>
</head>
<body>
<table border="1">
<tr>
<th class="left-align">Left Aligned Header</th>
<th class="center-align">Center Aligned Header</th>
<th class="right-align">Right Aligned Header</th>
</tr>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
</table>
</body>
</html>
Output:
Using CSS Instead of the align Attribute Supported Browsers: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