Tables

Table Layout

Utilities for controlling the table layout algorithm.

Quick reference

Class
Properties
table-autotable-layout: auto;
table-fixedtable-layout: fixed;

Basic usage

Auto

Use table-auto to allow the table to automatically size columns to fit the contents of the cell.

Table Layout - 图1

  1. <table class="table-auto">
  2. <thead>
  3. <tr>
  4. <th>Song</th>
  5. <th>Artist</th>
  6. <th>Year</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr>
  11. <td>The Sliding Mr. Bones (Next Stop, Pottersville)</td>
  12. <td>Malcolm Lockyer</td>
  13. <td>1961</td>
  14. </tr>
  15. <tr>
  16. <td>Witchy Woman</td>
  17. <td>The Eagles</td>
  18. <td>1972</td>
  19. </tr>
  20. <tr>
  21. <td>Shining Star</td>
  22. <td>Earth, Wind, and Fire</td>
  23. <td>1975</td>
  24. </tr>
  25. </tbody>
  26. </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 Layout - 图2

  1. <table class="table-fixed">
  2. <thead>
  3. <tr>
  4. <th>Song</th>
  5. <th>Artist</th>
  6. <th>Year</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr>
  11. <td>The Sliding Mr. Bones (Next Stop, Pottersville)</td>
  12. <td>Malcolm Lockyer</td>
  13. <td>1961</td>
  14. </tr>
  15. <tr>
  16. <td>Witchy Woman</td>
  17. <td>The Eagles</td>
  18. <td>1972</td>
  19. </tr>
  20. <tr>
  21. <td>Shining Star</td>
  22. <td>Earth, Wind, and Fire</td>
  23. <td>1975</td>
  24. </tr>
  25. </tbody>
  26. </table>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:table-fixed to only apply the table-fixed utility on hover.

  1. <table class="hover:table-fixed">
  2. <!-- ... -->
  3. </table>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:table-fixed to apply the table-fixed utility at only medium screen sizes and above.

  1. <table class="md:table-fixed">
  2. <!-- ... -->
  3. </table>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.