HTML <table> Tag

The <table> tag defines an HTML table. It contains other HTML elements that determine the structure of the table.

The <tr> tag determines table rows. A row can have one or more <td> or <th> elements, which define a table cell and a table header respectively.

The <th> tag is placed in the first row of the table. The text in it is bold and centered by default.

The <th> tag is not a mandatory element in the table, but we recommend to use it, as it helps to have better table layout as well as helps search engines better index the content of the table.

A more complex table can include also <caption>, thead, tbody, tfoot, or <colgroup> elements.

Syntax

The <table> tag comes in pairs. Its content is written between opening (<table>) and closing (</table>) tags.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      th, td {
        padding: 10px;
        border: 1px solid #666;
      }
    </style>
  </head>
  <body>
    <table style="width:80%; margin:30px auto; border-collapse:collapse;">
      <tr>
        <th>Month</th>
        <th>Date</th>
      </tr>
      <tr>
        <td>June</td>
        <td>10.06.2018</td>
      </tr>
      <tr>
        <td>July</td>
        <td>15.07.2018</td>
      </tr>
    </table>
  </body>
</html>

Result

Attributes

The attributes of the <table> tag are not supported in HTML5. For styling tables use CSS properties listed below.

Attribute Value Description CSS property
align left
center
right
Defines how the table must be aligned according to the surrounding text.
Not supported in HTML5.
margin
bgcolor rgb(x,x,x)
#xxxxxx
colorname
Defines the background color for a table.
Not supported in HTML5.
background-color
border 1
0
Defines the size of the frame surrounding the table.
Not supported in HTML5.
border
cellpadding pixels Defines the space between the cell wall and the cell content.
Not supported in HTML5.
border-collapse
cellspacing pixels Defines the space between cells.
Not supported in HTML5.
border-spacing
frame void
above
below
hsides
lhs
rhs
vsides
box
border
Defines which side of the frame surrounding the table must be displayed.
Not supported in HTML5.
border-style
border-width
rules none
groups
rows
cols
all
Defines which parts of the inside borders should be visible.
Not supported in HTML5.
border
(Use this property correspondingly with
thead,
tbody,
tfoot,
col or colgroup HTML tags).
summary text Defines a summary for the content of a table.
Not supported in HTML5.
caption-side
width pixels
Defines the width of a table.
Not supported in HTML5.
width

The <table> also supports the Global Attributes and the Event Attributes.

Browser support