Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML concept: tables

HTML tables describe data whose meaning comes from row-column intersections, not merely from visual alignment.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<table><caption>…</caption><thead>…</thead><tbody>…</tbody></table>

table contains an optional caption, thead, tbody, and tfoot groups, plus tr rows with th or td cells; order and context follow content models.

rowspan can be rowspan="0" to span the remaining rows in its row group; its other spans and colspan are positive, and cells must not overlap.

For simple headers, scope uses row or col; complex tables can connect headers to id values. A table is not a page-layout device.

The example reads caption, the rows and tBodies collections, cellIndex, and explicit headers and scope.

Examples

<!doctype html>
<meta charset="utf-8">
<table id="prices">
  <caption>Prices</caption>
  <thead><tr><th id="product" scope="col">Product</th><th id="amount" scope="col">Amount</th></tr></thead>
  <tbody><tr><th id="widget" scope="row">Widget</th><td id="price" headers="widget amount">9</td></tr></tbody>
</table>
<output id="result"></output>
<script>
const table = document.querySelector("#prices");
const cell = document.querySelector("#price");
result.textContent = `caption=${table.caption.textContent}; rows=${table.rows.length}; bodies=${table.tBodies.length}; cellIndex=${cell.cellIndex}; headers=${cell.headers}; rowScope=${widget.scope}`;
</script>

Result

caption=Prices; rows=2; bodies=1; cellIndex=1; headers=widget amount; rowScope=row

The result verifies the DOM grid and author associations; it does not simulate screen-reader presentation or a complex header algorithm.

Sources