HTML <table> align Attribute
Last Updated :
22 Dec, 2023
The HTML <table> align Attribute is used to specify the alignment of the table and its content. Instead of the align
attribute, CSS properties like margin
and text-align
are preferred for table alignment. For aligning content within table rows or cells, use the align
attribute within <tr>
and
or apply CSS styles.
Note: This attribute is not supported by HTML5.
Syntax
<table align="left | right | center">
Attribute Values
left
|
It sets the left align to the table. It is a default value.
|
right
|
It sets the right align to the table.
|
center
|
It sets the center align to the table.
|
Example 1: In this example, we will see the implementation of the align-right attribute with an example.
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML table align Attribute
</ title >
</ head >
< body >
< h1 style = "green" >GeeksforGeeks</ h1 >
< h2 >HTML table align Attribute</ h2 >
< table border = "1" align = "right" >
< caption >Author Details</ caption >
< tr >
< th >NAME</ th >
< th >AGE</ th >
< th >BRANCH</ th >
</ tr >
< tr >
< td >BITTU</ td >
< td >22</ td >
< td >CSE</ td >
</ tr >
< tr >
< td >RAM</ td >
< td >21</ td >
< td >ECE</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output:
Example 2: In this example, we will see the implementation of the align-left attribute.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML table align Attribute
</ title >
</ head >
< body >
< h1 style = "green" >GeeksforGeeks</ h1 >
< h2 >HTML table align Attribute</ h2 >
< table border = "1" align = "left" >
< caption >Author Details</ caption >
< tr >
< th >NAME</ th >
< th >AGE</ th >
< th >BRANCH</ th >
</ tr >
< tr >
< td >BITTU</ td >
< td >22</ td >
< td >CSE</ td >
</ tr >
< tr >
< td >RAM</ td >
< td >21</ td >
< td >ECE</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output:
Example 3: In this example, we will see the implementation of the align-center attribute.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML table align Attribute
</ title >
</ head >
< style >
h1,
h2 {
text-align: center;
}
</ style >
< body >
< h1 style = "green" >GeeksforGeeks</ h1 >
< h2 >HTML table align Attribute</ h2 >
< table border = "1" align = "center" >
< caption >Author Details</ caption >
< tr >
< th >NAME</ th >
< th >AGE</ th >
< th >BRANCH</ th >
</ tr >
< tr >
< td >BITTU</ td >
< td >22</ td >
< td >CSE</ td >
</ tr >
< tr >
< td >RAM</ td >
< td >21</ td >
< td >ECE</ td >
</ tr >
</ table >
</ body >
</ html >
|
Output:
Supported Browsers
- Google Chrome 1 and above
- Microsoft Edge 12 and above
- Firefox 1 and above
- Opera 12.1 and above
- Safari 3 and above
HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...