Border Collapse

Utilities for controlling whether table borders should collapse or be separated.

Class reference

Class
Properties
.border-collapseborder-collapse: collapse;
.border-separateborder-collapse: separate;

Collapse

Use .border-collapse to combine adjacent cell borders into a single border when possible. Note that this includes collapsing borders on the top-level <table> tag.

Border Collapse - 图1

  1. <table class="border-collapse border-2 border-gray-500">
  2. <thead>
  3. <tr>
  4. <th class="border border-gray-400 px-4 py-2 text-gray-800">State</th>
  5. <th class="border border-gray-400 px-4 py-2 text-gray-800">City</th>
  6. </tr>
  7. </thead>
  8. <tbody>
  9. <tr>
  10. <td class="border border-gray-400 px-4 py-2">Indiana</td>
  11. <td class="border border-gray-400 px-4 py-2">Indianapolis</td>
  12. </tr>
  13. <tr>
  14. <td class="border border-gray-400 px-4 py-2">Ohio</td>
  15. <td class="border border-gray-400 px-4 py-2">Columbus</td>
  16. </tr>
  17. <tr>
  18. <td class="border border-gray-400 px-4 py-2">Michigan</td>
  19. <td class="border border-gray-400 px-4 py-2">Detroit</td>
  20. </tr>
  21. </tbody>
  22. </table>

Separate

Use .border-separate to force each cell to display its own separate borders.

Border Collapse - 图2

  1. <table class="border-separate border-2 border-gray-500">
  2. <thead>
  3. <tr>
  4. <th class="border border-gray-400 px-4 py-2 text-gray-800">State</th>
  5. <th class="border border-gray-400 px-4 py-2 text-gray-800">City</th>
  6. </tr>
  7. </thead>
  8. <tbody>
  9. <tr>
  10. <td class="border border-gray-400 px-4 py-2">Indiana</td>
  11. <td class="border border-gray-400 px-4 py-2">Indianapolis</td>
  12. </tr>
  13. <tr>
  14. <td class="border border-gray-400 px-4 py-2">Ohio</td>
  15. <td class="border border-gray-400 px-4 py-2">Columbus</td>
  16. </tr>
  17. <tr>
  18. <td class="border border-gray-400 px-4 py-2">Michigan</td>
  19. <td class="border border-gray-400 px-4 py-2">Detroit</td>
  20. </tr>
  21. </tbody>
  22. </table>

Customizing

Responsive and pseudo-class variants

By default, only responsive variants are generated for border collapse utilities.

You can control which variants are generated for the border collapse utilities by modifying the borderCollapse property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - borderCollapse: ['responsive'],
  6. + borderCollapse: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

If you don’t plan to use the border collapse utilities in your project, you can disable them entirely by setting the borderCollapse property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + borderCollapse: false,
  6. }
  7. }

← Divide Style   Table Layout →