HTML Tag Reference - HTML tag <table>








This element creates a table that can contain rows and columns. The <tr> element creates rows in the table. The <td> element creates the cells in each table row.

Browser compatibility

<table> Yes Yes Yes Yes Yes

What's new in HTML5

The "align", "bgcolor", "border", "cellpadding", "cellspacing", "frame", "rules", "summary", and "width" attributes are deprecated in HTML5.

Attribute

Attribute Value Description
align left
center
right
Not supported in HTML5.
Set the alignment of a table
bgcolor rgb(x,x,x)
#xxxxxx
colorname
Not supported in HTML5.
Set the table background color
border 1
""
Not supported in HTML5.
Set whether the table cells should have borders or not
cellpadding pixels Not supported in HTML5.
Set the space between the cell wall and the cell content
cellspacing pixels Not supported in HTML5.
Set the space between cells
frame void
above
below
hsides
lhs
rhs
vsides
box
border
Not supported in HTML5.
Set which parts of the outside borders that should be visible
rules none
groups
rows
cols
all
Not supported in HTML5.
Set which parts of the borders that should be visible
sortable sortable the table should be sortable
summary text Not supported in HTML5.
Create a summary of the table content
width pixels
%
Not supported in HTML5.
Set the width of a table




Global Attributes

The <table> tag supports the Global Attributes in HTML.

Event Attributes

The <table> tag supports the Event Attributes in HTML.

Default CSS Settings

table {
    display: table;
    border-collapse: separate;
    border-spacing: 2px;
    border-color: gray;
}




Example

A demo showing how to use <table> tag.

<html>
<body>
     <table>
          <tr>
               <td>col 1: maroon</td>
               <td>col 2: red</td>
          <tr>
               <td>col 1: maroon</td>
               <td>col 2: red</td>
          </tr>
     </table>
</body><!--from   w w w . j  av  a 2s. c o m-->
</html>

Click to view the demo