utilities/layout/tables.md
The table utility behaves like HTML <table> element. It defines a block-level box. Table element represents tabular data — that is, information presented in a two-dimensional table comprised of rows and columns of cells containing data.
<PlaygroundWithVariants variant='table' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table-caption border-collapse text-center table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold' html='<div class="{class} text-xs border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The inline-table utility does not have a direct mapping in HTML. It behaves like an HTML <table> element, but as an inline box, rather than a block-level box. Inside the table box is a block-level context.
<PlaygroundWithVariants variant='inline-table' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table-caption border-collapse text-center table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold' html='<div class="{class} text-xs border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
| inline-table | display: inline-table; |
The table-caption utility behaves like <caption> HTML element. The HTML <caption> element specifies the caption (or title) of a table.
<PlaygroundWithVariants variant='table-caption' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table border-collapse text-center table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold ring ring-amber-400' html='<div class="table text-xs border-collapse"> <div class="{class} text-center text-emerald-600 py-2 font-bold ring ring-amber-400">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The table-cell utility behaves like <td> HTML element. The HTML <td> element defines a cell of a table that contains data. It participates in the table model.
<PlaygroundWithVariants variant='table-cell' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table border-collapse table-caption text-center table-header-group table-row table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold ring ring-offset-2 ring-amber-400' html='<div class="table text-xs border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell ring ring-offset-2 ring-amber-400 border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The table-row utility behaves like <tr> HTML element. The HTML <tr> element defines a row of cells in a table. The row's cells can then be established using a mix of <td> (data cell) and <th> (header cell) elements.
<PlaygroundWithVariants variant='table-row' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table border-collapse text-center table-caption table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold ring ring-offset-2 ring-amber-400' html='<div class="table text-xs border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row ring ring-offset-2 ring-amber-400"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The table-column utility behaves like <col> HTML element. The HTML <col> element defines a column within a table and is used for defining common semantics on all common cells. It is generally found within a <colgroup> element.
<PlaygroundWithVariants variant='table-column' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table text-center border-collapse table-caption table-column-group table-column table-row table-cell text-xs border border-emerald-500 bg-emerald-200 bg-teal-200 bg-yellow-200 bg-green-200 p-1 py-2 text-emerald-600 font-medium font-bold' html='<div class="table border-collapse text-xs text-emerald-600"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Superheros</div> <div class="table-column-group"> <div class="table-column bg-emerald-200"></div> <div class="table-column bg-teal-200"></div> <div class="table-column bg-yellow-200"></div> </div> <div class="table-row"> <div class="table-cell p-1 border border-emerald-500 font-medium">Hero</div> <div class="table-cell p-1 border border-emerald-500">Batman</div> <div class="table-cell p-1 border border-emerald-500">Flash</div> </div> <div class="table-row"> <div class="table-cell p-1 border border-emerald-500 font-medium">Skill</div> <div class="table-cell p-1 border border-emerald-500">Smarts</div> <div class="table-cell p-1 border border-emerald-500">Speed</div> </div> </div>' />
The table-row-group utility behaves like <tbody> HTML element. The HTML Table Body element (<tbody>) encapsulates a set of table rows (<tr> elements), indicating that they comprise the body of the table (<table>).
<PlaygroundWithVariants variant='table-row-group' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table border-collapse text-center table-caption table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold ring ring-offset-2 ring-amber-400' html='<div class="table text-xs text-emerald-600 border-collapse"> <div class="table-caption text-center py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group ring ring-offset-2 ring-amber-400"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1">Donuts</div> <div class="table-cell border border-emerald-500 p-1">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1">Stationery</div> <div class="table-cell border border-emerald-500 p-1">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1">Totals</div> <div class="table-cell border border-emerald-500 p-1">21,000</div> </div> </div> </div>' />
The table-column-group utility behaves like <colgroup> HTML element. The HTML <colgroup> element defines a group of columns within a table.
<PlaygroundWithVariants variant='table-column-group' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table text-center table-caption border-collapse table-column-group table-column table-row table-cell text-xs border border-emerald-500 bg-emerald-200 bg-teal-200 bg-yellow-200 bg-green-200 p-1 py-2 text-emerald-600 font-medium font-bold' html='<div class="table text-xs text-emerald-600 border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Superheros</div> <div class="table-column-group"> <div class="table-column bg-emerald-200"></div> <div class="table-column bg-teal-200"></div> <div class="table-column bg-yellow-200"></div> </div> <div class="table-row"> <div class="table-cell p-1 border border-emerald-500 font-medium">Hero</div> <div class="table-cell p-1 border border-emerald-500">Batman</div> <div class="table-cell p-1 border border-emerald-500">Flash</div> </div> <div class="table-row"> <div class="table-cell p-1 border border-emerald-500 font-medium">Skill</div> <div class="table-cell p-1 border border-emerald-500">Smarts</div> <div class="table-cell p-1 border border-emerald-500">Speed</div> </div> </div>' />
The table-header-group utility behaves like <thead> HTML element. The HTML <thead> element defines a set of rows defining the head of the columns of the table.
<PlaygroundWithVariants variant='table-header-group' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table text-center table-caption border-collapse table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold ring ring-offset-2 ring-amber-400' html='<div class="table text-xs border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200 ring ring-offset-2 ring-amber-400"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The table-footer-group utility behaves like <tfoot> HTML element. The HTML <tfoot> element defines a set of rows summarizing the columns of the table.
<PlaygroundWithVariants variant='table-footer-group' :variants='[]' fixed='dark:text-white opacity-85' nested=true appended='table text-center table-caption border-collapse table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold ring ring-offset-2 ring-amber-400' html='<div class="table text-xs border-collapse"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group ring ring-offset-2 ring-amber-400"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
Utilities for controlling the table layout algorithm.
<PlaygroundWithVariants variant='auto' :variants="['auto', 'fixed']" prefix='table' fixed='dark:text-white opacity-85' nested=true appended='border-collapse text-center text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold w-2/3' html='<table class="{class} text-xs border-collapse w-2/3"> <caption class="text-center text-emerald-600 py-2 font-bold">Council budget</caption> <thead class="bg-emerald-200"> <tr> <th class="border border-emerald-500 p-1 text-emerald-600 font-medium">Items</th> <th class="border border-emerald-500 p-1 text-emerald-600 font-medium">Expenditure</th> </tr> </thead> <tbody> <tr> <td class="border border-emerald-500 p-1 text-emerald-600">Donuts</td> <td class="border border-emerald-500 p-1 text-emerald-600">3,000</td> </tr> <tr> <td class="border border-emerald-500 p-1 text-emerald-600">Stationery</td> <td class="border border-emerald-500 p-1 text-emerald-600">18,000</td> </tr> </tbody> <tfoot> <tr> <td class="border border-emerald-500 p-1 text-emerald-600">Totals</td> <td class="border border-emerald-500 p-1 text-emerald-600">21,000</td> </tr> </tfoot> </table>' />
Utilities for controlling whether table borders should collapse or be separated.
<PlaygroundWithVariants variant='collapse' :variants="['collapse', 'separate']" prefix='border' fixed='dark:text-white opacity-85' nested=true appended='table table-caption text-center table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold' html='<div class="table {class} text-xs"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The caption utility puts the content of a table's <caption> on the specified side. The values are relative to the writing-mode of the table.
<PlaygroundWithVariants variant='top' :variants="['top', 'bottom']" prefix='caption' fixed='dark:text-white opacity-85' nested=true appended='table table-caption text-center table-header-group table-row table-cell table-row-group table-footer-group text-xs border border-emerald-500 bg-emerald-200 p-1 py-2 text-emerald-600 font-medium font-bold' html='<div class="table {class} text-xs"> <div class="table-caption text-center text-emerald-600 py-2 font-bold">Council budget</div> <div class="table-header-group bg-emerald-200"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium">Items</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600 font-medium" scope="col">Expenditure</div> </div> </div> <div class="table-row-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Donuts</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">3,000</div> </div> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Stationery</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">18,000</div> </div> </div> <div class="table-footer-group"> <div class="table-row"> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">Totals</div> <div class="table-cell border border-emerald-500 p-1 text-emerald-600">21,000</div> </div> </div> </div>' />
The empty-cells utility sets whether borders and backgrounds appear around <table>cells that have no visible content. A good use case for empty-cells could be a situation where you may not know whether a table will or will not contain empty data points and you decide to hide them.
<PlaygroundWithVariants variant='visible' :variants="['visible', 'hidden']" prefix='empty-cells' fixed='dark:text-white opacity-85 text-xs' nested=true appended='border-separate text-emerald-600 border border-emerald-500 p-1 font-medium font-bold py-2 text-center' html='<table class="border-separate text-emerald-600 {class}"> <caption class="text-center py-2 font-bold">Client Info</caption> <tbody> <tr> <th class="border border-emerald-500 p-1 font-medium">Client Name</th> <th class="border border-emerald-500 p-1 font-medium">Age</th> </tr> <tr> <td class="border border-emerald-500 p-1"></td> <td class="border border-emerald-500 p-1">25</td> </tr> <tr> <td class="border border-emerald-500 p-1">Louise Q.</td> <td class="border border-emerald-500 p-1"></td> </tr> <tr> <td class="border border-emerald-500 p-1">Owen B.</td> <td class="border border-emerald-500 p-1"></td> </tr> </tbody> </table>' />
Use above utilities to create elements that behave like their respective table elements.
<table>
<caption>Council budget</caption>
<thead>
<tr>
<th>Items</th>
<th scope="col">Expenditure</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Donuts</th>
<td>3,000</td>
</tr>
<tr>
<th scope="row">Stationery</th>
<td>18,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="row">Totals</th>
<td>21,000</td>
</tr>
</tfoot>
</table>
<div class="table">
<div class="table-caption">Council budget</div>
<div class="table-header-group">
<div class="table-row">
<div class="table-cell">Items</div>
<div class="table-cell">Expenditure</div>
</div>
</div>
<div class="table-row-group">
<div class="table-row">
<div class="table-cell">Donuts</div>
<div class="table-cell">3,000</div>
</div>
<div class="table-row">
<div class="table-cell">Stationery</div>
<div class="table-cell">18,000</div>
</div>
</div>
<div class="table-footer-group">
<div class="table-row">
<div class="table-cell">Totals</div>
<div class="table-cell">21,000</div>
</div>
</div>
</div>