Table Layout
Utilities for controlling the table layout algorithm.
Class reference
Class | Properties |
---|---|
.table-auto | table-layout: auto; |
.table-fixed | table-layout: fixed; |
Auto
Use .table-auto
to allow the table to automatically size columns to fit the contents of the cell.
<table class="table-auto">
<thead>
<tr>
<th class="px-4 py-2">Title</th>
<th class="px-4 py-2">Author</th>
<th class="px-4 py-2">Views</th>
</tr>
</thead>
<tbody>
<tr>
<td class="border px-4 py-2">Intro to CSS</td>
<td class="border px-4 py-2">Adam</td>
<td class="border px-4 py-2">858</td>
</tr>
<tr class="bg-gray-100">
<td class="border px-4 py-2">A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
<td class="border px-4 py-2">Adam</td>
<td class="border px-4 py-2">112</td>
</tr>
<tr>
<td class="border px-4 py-2">Intro to JavaScript</td>
<td class="border px-4 py-2">Chris</td>
<td class="border px-4 py-2">1,280</td>
</tr>
</tbody>
</table>
Fixed
Use .table-fixed
to allow the table to ignore the content and use fixed widths for columns. The width of the first row will set the column widths for the whole table.
You can manually set the widths for some columns and the rest of the available width will be divided evenly amongst the columns without explicit width.
<table class="table-fixed">
<thead>
<tr>
<th class="w-1/2 px-4 py-2">Title</th>
<th class="w-1/4 px-4 py-2">Author</th>
<th class="w-1/4 px-4 py-2">Views</th>
</tr>
</thead>
<tbody>
<tr>
<td class="border px-4 py-2">Intro to CSS</td>
<td class="border px-4 py-2">Adam</td>
<td class="border px-4 py-2">858</td>
</tr>
<tr class="bg-gray-100">
<td class="border px-4 py-2">A Long and Winding Tour of the History of UI Frameworks and Tools and the Impact on Design</td>
<td class="border px-4 py-2">Adam</td>
<td class="border px-4 py-2">112</td>
</tr>
<tr>
<td class="border px-4 py-2">Intro to JavaScript</td>
<td class="border px-4 py-2">Chris</td>
<td class="border px-4 py-2">1,280</td>
</tr>
</tbody>
</table>
Customizing
Responsive and pseudo-class variants
By default, only responsive variants are generated for table layout utilities.
You can control which variants are generated for the table layout utilities by modifying the tableLayout
property in the variants
section of your tailwind.config.js
file.
For example, this config will also generate hover and focus variants:
// tailwind.config.js
module.exports = {
variants: {
// ...
- tableLayout: ['responsive'],
+ tableLayout: ['responsive', 'hover', 'focus'],
}
}
Disabling
If you don’t plan to use the table layout utilities in your project, you can disable them entirely by setting the tableLayout
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ tableLayout: false,
}
}