Layout

Visibility

Utilities for controlling the visibility of an element.

Quick reference

Class
Properties
visiblevisibility: visible;
invisiblevisibility: hidden;
collapsevisibility: collapse;

Basic usage

Making elements invisible

Use invisible to hide an element, but still maintain its place in the DOM, affecting the layout of other elements (compare with .hidden from the display documentation).

Visibility - 图1

  1. <div class="grid grid-cols-3 gap-4">
  2. <div>01</div>
  3. <div class="invisible ...">02</div>
  4. <div>03</div>
  5. </div>

Collapsing elements

Use collapse to hide table rows, row groups, columns, and column groups as if they were set to display: none, but without impacting the size of other rows and columns.

This makes it possible to dynamically toggle rows and columns without affecting the table layout.

Visibility - 图2

  1. <table>
  2. <thead>
  3. <tr>
  4. <th>Invoice #</th>
  5. <th>Client</th>
  6. <th>Amount</th>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr>
  11. <td>#100</td>
  12. <td>Pendant Publishing</td>
  13. <td>$2,000.00</td>
  14. </tr>
  15. <tr class="collapse">
  16. <td>#101</td>
  17. <td>Kruger Industrial Smoothing</td>
  18. <td>$545.00</td>
  19. </tr>
  20. <tr>
  21. <td>#102</td>
  22. <td>J. Peterman</td>
  23. <td>$10,000.25</td>
  24. </tr>
  25. </tbody>
  26. </table>

Making elements visible

Use visible to make an element visible. This is mostly useful for undoing the invisible utility at different screen sizes.

Visibility - 图3

  1. <div class="grid grid-cols-3 gap-4">
  2. <div>01</div>
  3. <div class="visible ...">02</div>
  4. <div>03</div>
  5. </div>

Applying conditionally

Hover, focus, and other states

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

  1. <div class="visible hover:invisible">
  2. <!-- ... -->
  3. </div>

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:invisible to apply the invisible utility at only medium screen sizes and above.

  1. <div class="visible md:invisible">
  2. <!-- ... -->
  3. </div>

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