CKTIS / CSS
Tables and relationships in CSS
The CSS table model arranges cells into related rows and columns. HTML describes the data and header relationships, while CSS controls presentation: borders, spacing, caption placement, and width calculation.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
table { table-layout: auto; border-collapse: collapse; }
th, td { border: 1px solid; padding: 0.5rem; }A table represents data whose meaning comes from the intersection of a row and a column. The CSS table model includes cells, rows, row groups, columns, column groups, and captions. It is row-primary: cell positions in successive rows establish the columns, accounting for cells that span multiple slots.
Structure and presentation are different layers. HTML defines relationships between data and headers; in the example, scope="col" identifies a column header and scope="row" identifies a row header. CSS controls their appearance. Setting display: table-cell alone creates a CSS layout role but does not declare an HTML header-to-data relationship.
border-collapse: collapse enables the shared-border model for adjacent cells. With border-collapse: separate, cells have separate borders and border-spacing sets the gaps between them. caption-side determines which side receives the caption. table-layout: auto considers content when calculating widths; table-layout: fixed with an explicit table width relies primarily on column widths and cells in the first row.
The example preserves semantic HTML structure and changes only presentation. The expected result is the caption Stock above a two-column table. CSS Tables Level 3 is a working draft, not evidence of browser support; the example requires separate local verification.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Table relationships</title>
<style>
table { border-collapse: collapse; }
caption { caption-side: top; }
th, td { border: 1px solid black; padding: 8px; text-align: left; }
</style>
<table>
<caption>Stock</caption>
<thead>
<tr><th scope="col">Item</th><th scope="col">Count</th></tr>
</thead>
<tbody>
<tr><th scope="row">Pens</th><td>3</td></tr>
<tr><th scope="row">Books</th><td>2</td></tr>
</tbody>
</table>
</html>Result
Stock Item | Count Pens | 3 Books | 2
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.