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
Note: The align attribute is not supported by HTML5.
Syntax:
<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
<!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:
Example: The implementation of the align attribute
<!DOCTYPE html> < html >
< head >
< title >
HTML th align Attribute Example
</ title >
< style >
body {
text-align: center;
}
table {
margin: 0 auto;
}
</ style >
</ head >
< body >
< h1 style = "color: green;" >
GeeksforGeeks
</ h1 >
< h2 >
HTML th align Attribute Example
</ h2 >
< table width = "300" border = "1" >
< tr >
< th align = "left" >Student</ th >
< th align = "center" >Age</ th >
< th align = "right" >Department</ th >
</ tr >
< tr >
< td >John Doe</ td >
< td >20</ td >
< td >Computer Science</ td >
</ tr >
< tr >
< td >Jane Smith</ td >
< td >22</ td >
< td >Electrical Engineering</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome 1
- Microsoft Edge 12
- Firefox 1
- Opera 12.1
- Safari 1