HTML <table> tag

Updated: 12/10/2023 by Computer Hope
HTML table tag

When writing in HTML (hypertext markup language), the <table> tag is a block element used to create a table. It is useful when you want to represent data using rows and columns. The basic elements that make up and affect the size of a table include <th>, <td>, and <tr>. The following sections contain information about the <table> tag, including an example of it in use, and related attributes and browser compatibility.

Tip

More advanced tables may include the <caption>, <col>, <colgroup>, <tbody>, <tfoot>, or <thead> elements.

Note

Tables should only be used to show tabular data and not used to formatting a web page, images, or other data for accessibility reasons.

Example of <table> code

<table class="mtable2 tab">
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr class="tcw">
<td>March</td>
<td>$200</td>
</tr>
<tr class="tcw">
<td>April</td>
<td>$300</td>
</tr>
<tr class="tcw"> <td>May</td>
<td>$250</td>
</tr>
</table>

Example result

Month Savings
March $200
April $300
May $250

We have added a few of our own classes to the table using CSS (cascading style sheets); this action allows us to improve its appearance.

Deprecated attributes

All HTML tags support standard attributes that define the settings of an HTML element. In addition to the standard settings, the <table> tag had the following unique attributes that are now deprecated.

Attribute Description
align Designates the alignment of content, including text, inside an element.
bgcolor Designates the background color of a table.
border Designates whether or not cell should have a border.
cellpadding Designates how much spacing is between the cell wall and the cell content.
cellspacing Designates spacing between cells.
frame Designates which parts of the outside borders are visible.
rules Designates which parts of the inside borders are visible.
sortable Designates that a table is sortable.
summary Designates what the contents of the table are.
width Designates how wide the table should be.

Compatibility

Edge Internet Explorer Firefox Safari Opera Chrome
All versions 4.0+ All versions All version 7.0+ All versions

Browser, Cell, Class, Column, Compatibility, Container tag, Format, Row, Table, Web design terms