Fandom

HTML & CSS Wiki

Table

649pages on
this wiki
Add New Page
Comments0 Share


The semantic HTML <table></table> element displays a spreadsheet grid (with or without lines) for demonstrating relationships by horizontal or vertical alignment of several items arranged in rows and columns. It is not to be used to arrange page elements for purely aesthetic purposes, as this violates its semantic nature which is depended upon by automated clients such as search engines and accessibility technology (Braille and voice browsers). For alternative techniques, see positioning.

Attributes

Optional attributes

Attribute Value Description
summary text A short description to supplement the table's contents for visually impaired users. Like alt, this is exclusively for enhancing the experience of such users; for other users the caption or an entirely separate description is more appropriate.

Global attributes

See Global HTML Attributes.

Content

<caption>

The HTML <caption></caption> element defines a table caption. This optional element must be inserted immediately after the <table> tag. You can specify only one caption per table. Usually the caption will be centered above the table. When the <table> element that is the parent of the <caption> which is the only descendant of a <figure> element, use the <figcaption> element instead.

<thead>

The semantic HTML <thead></thead> element defines a table head. This optional element must be placed within a <table> element and before any <tbody>, <tfoot>, and/or <tr> elements. The end tag may be omitted if the <thead> element is immediately followed by a <tbody> or <tfoot> element.

<tbody>

The semantic HTML <tbody></tbody> element defines a table body. This optional element must be placed within a <table> element and after a <thead> or <caption> element and may only contain <tr>, <td>, or <th> elements. The end tag may be omitted if the <tbody> element is immediately followed by another <tbody> or <tfoot> element, of if there is no more content in the parent <table> element.

<tr>

The semantic HTML <tr></tr> element defines a table row. It must be placed within a <table>, <thead>, <tbody>, or <tfoot> element and may only contain <td> and <th> elements. The end tag may be omitted if the <tr> element is immediately followed by another <tr> element, or if the parent <table> element doesn't have any more content.

<th>

The semantic HTML <th></th> element defines a table header. It must be placed within a <table>, <thead>, <tbody>, or <tfoot> which contains a <tr> element and may only contain the table header. The end tag may be omitted, if it is immediately followed by another <th> or <td> element or if there are no more data in its parent element.

<td>

The semantic HTML <td></td> element defines a table cell. It must be placed within a <table>, <thead>, <tbody>, or <tfoot> which contains a <tr> element and may only contain table data. The end tag may be omitted, if it is immediately followed by a <th> or another <td> element or if there are no more data in its parent element.

<tfoot>

The semantic HTML <tfoot></tfoot> element defines a table footer. This optional element must be placed within a <table> element and either before or after any <tbody> or <tr> elements, but not intermixed with them. The end tag may be omitted if the <tbody> element is immediately followed by a <tbody>, or if there is no more content in the parent <table> element.

Document Object Model

table objects expose the HTMLTableElement interface, which provides special properties and methods (beyond the regular element object interface they also have available to them by inheritance) for manipulating the layout and presentation of tables in HTML.


W3C Mozilla Microsoft
[1] [2] [3]

Properties

rows

Data type HTMLCollection
Standard DOM Level 1 HTMLDOM Level 2 HTML
Documentation Mozilla Microsoft

A collection of all the rows in the table.

Methods

External links

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.