Open In App

HTML <table> align Attribute

Last Updated : 18 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML <table> align Attribute specify the table’s alignment but CSS properties like margin and text-align are preferred for table alignment. To align content within table rows or cells, use the align attribute within <tr> and <td> tag or apply CSS styles.

Syntax:

<table align="left | right | center">

Attribute Values

Attributes

Descriptions

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 align="right" border="1">
    <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:

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 align="left" border="1">
<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:

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 align="center" border="1">
<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:

output

Browsers Support

browsers support

Compatibility Notes

Note: The align attribute of <table> is not supported in HTML5. Use CSS instead. CSS Syntax: <table style=”float:right“>

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.



Next Article

Similar Reads

  翻译: