The align attribute in the <td> tag is used to set the horizontal alignment of content inside a table cell (like left, right, or center).
- Used to align text horizontally inside a table cell.
- Common values: left, right, center, justify.
- Works only with the <td> (table data) element.
- Helps control content positioning within table cells.
Note: The align attribute is deprecated in HTML5, so it is recommended to use CSS (such as the text-align property) instead for better styling and compatibility.
Syntax
<td align ="left | right | center | justify | char">Attribute Values
The <td> align attributes have the following attributes which are as:
- left: Aligns the text to the left side of the container.
- right: Aligns the text to the right side of the container.
- center: Aligns the text to the center.
- justify: Stretches the text so that all lines have equal width.
- char: Aligns the text based on a specific character.
Example: Implementation of the <td> align tag.
<!--Driver Code Starts-->
<html>
<head>
<title>
HTML td align Attribute
</title>
<style>
h1,
h2 {
text-align: center;
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML td align Attribute</h2>
<!--Driver Code Ends-->
<table width="500" border="1">
<tr>
<th>NAME</th>
<th>AGE</th>
<th>BRANCH</th>
</tr>
<tr>
<td style="text-align: center;">Ben</td>
<td style="text-align: left;">22</td>
<td style="text-align: right;">CSE</td>
</tr>
<tr>
<td style="text-align: left;">Ron</td>
<td style="text-align: center;">25</td>
<td style="text-align: left;">EC</td>
</tr>
</table>
<!--Driver Code Starts-->
</body>
</html>
<!--Driver Code Ends-->
Note: The <td> align attribute is not supported by HTML5 instead uses CSS.