Tables
Render HTML tables with Takumi, set column widths, and understand differences from browser table layout.
Takumi lays out tables with a port of Chromium's table layout. Column widths, row heights, and collapsed borders follow Chromium.
< ={{ : "100%" }}>
<>
< ={{ : "#e2e8f0" }}>
<>Name</>
< ={{ : "80px" }}>Qty</>
</>
</>
<>
<>
<>Wireframe kit</>
<>3</>
</>
</>
</>Elements
<table>,<caption>,<colgroup>,<col>,<thead>,<tbody>,<tfoot>,<tr>,<td>, and<th>have presets in HTML and JSX.- Header groups render first. Footer groups render last.
captionrenders above the table.caption-side: bottommoves it below.display: inline-tablesits on a line. Its first row's baseline aligns with the text.
Columns and spans
colspanandrowspanwork on<td>and<th>. The JSX props arecolSpanandrowSpan.- A
rowspanstops at the end of its row group. <col>and<colgroup>widths size their columns.spancovers several columns.- Columns share the table's width by their content.
table-layout: fixedreads column widths from the first row. It needs a tablewidth.visibility: collapseremoves a row or a column, and its space.direction: rtlstarts the first column on the right.
Sizing
- An
auto-width table shrinks to fit its content. - In a flex or grid container, an
auto-width table stretches. - In automatic layout, a table is never narrower than its content's minimum width.
- With
table-layout: fixedand awidth, content can overflow its cell instead.
Borders and backgrounds
border-spacingputs gaps between cells. The gaps stay unpainted.border-collapse: collapsemerges shared borders as Chromium does. The wider border wins.- Row, row group, column, and column group backgrounds paint inside their cells.
- With separate borders,
empty-cells: hidehides empty cells.
Alignment
vertical-alignplaces cell content as Chromium does.baselinecells line up their first lines across a row.
PDF pages
- Rows split across pages.
- Header and footer groups with
break-inside: avoidrepeat on every page. The presets set it. - Columns keep the same positions on every page.
Where it drifts
| Case | Chromium | Takumi |
|---|---|---|
| Row baseline, with percentage-height content in a cell | Measured after the row grows | Measured before the row grows |
content-box background on a vertically aligned cell | Stays at the cell's padding | Moves with the content |
| Background image on a row or column under a spanning cell | Positioned on the row or column | Positioned on the row or column, grown to the cell |
| Page breaks | Fragments the table in layout | Cuts the finished table into pages |
Last updated on