Tables

Caption Side

Utilities for controlling the alignment of a caption element inside of a table.

Quick reference

Class
Properties
caption-topcaption-side: top;
caption-bottomcaption-side: bottom;

Basic usage

Top

Use caption-top to position a caption element at the top of a table.

Caption Side - 图1

  1. <table>
  2. <caption class="caption-top">
  3. Table 3.1: Professional wrestlers and their signature moves.
  4. </caption>
  5. <thead>
  6. <tr>
  7. <th>Wrestler</th>
  8. <th>Signature Move(s)</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <tr>
  13. <td>"Stone Cold" Steve Austin</td>
  14. <td>Stone Cold Stunner, Lou Thesz Press</td>
  15. </tr>
  16. <tr>
  17. <td>Bret "The Hitman" Hart</td>
  18. <td >The Sharpshooter</td>
  19. </tr>
  20. <tr>
  21. <td>Razor Ramon</td>
  22. <td>Razor's Edge, Fallaway Slam</td>
  23. </tr>
  24. </tbody>
  25. </table>

Bottom

Use caption-bottom to position a caption element at the bottom of a table.

Caption Side - 图2

  1. <table>
  2. <caption class="caption-bottom">
  3. Table 3.1: Professional wrestlers and their signature moves.
  4. </caption>
  5. <thead>
  6. <tr>
  7. <th>Wrestler</th>
  8. <th>Signature Move(s)</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <tr>
  13. <td>"Stone Cold" Steve Austin</td>
  14. <td>Stone Cold Stunner, Lou Thesz Press</td>
  15. </tr>
  16. <tr>
  17. <td>Bret "The Hitman" Hart</td>
  18. <td >The Sharpshooter</td>
  19. </tr>
  20. <tr>
  21. <td>Razor Ramon</td>
  22. <td>Razor's Edge, Fallaway Slam</td>
  23. </tr>
  24. </tbody>
  25. </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:caption-bottom to only apply the caption-bottom utility on hover.

  1. <table class="caption-top hover:caption-bottom">
  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:caption-bottom to apply the caption-bottom utility at only medium screen sizes and above.

  1. <table class="caption-top md:caption-bottom">
  2. <!-- ... -->
  3. </table>

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