Borders

Divide Width

Utilities for controlling the border width between elements.

Quick reference

Class
Properties
divide-x-0 > + border-right-width: 0px; border-left-width: 0px;
divide-x-2 > + border-right-width: 0px; border-left-width: 2px;
divide-x-4 > + border-right-width: 0px; border-left-width: 4px;
divide-x-8 > + border-right-width: 0px; border-left-width: 8px;
divide-x > + border-right-width: 0px; border-left-width: 1px;
divide-y-0 > + border-top-width: 0px; border-bottom-width: 0px;
divide-y-2 > + border-top-width: 2px; border-bottom-width: 0px;
divide-y-4 > + border-top-width: 4px; border-bottom-width: 0px;
divide-y-8 > + border-top-width: 8px; border-bottom-width: 0px;
divide-y > + border-top-width: 1px; border-bottom-width: 0px;
divide-y-reverse > + —tw-divide-y-reverse: 1;
divide-x-reverse > + —tw-divide-x-reverse: 1;

Show all classes

Basic usage

Add borders between horizontal children

Add borders between horizontal elements using the divide-x-{width} utilities.

Divide Width - 图1

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

Add borders between stacked children

Add borders between stacked elements using the divide-y-{width} utilities.

Divide Width - 图2

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

Reversing children order

If your elements are in reverse order (using say flex-row-reverse or flex-col-reverse), use the divide-x-reverse or divide-y-reverse utilities to ensure the border is added to the correct side of each element.

Divide Width - 图3

  1. <div class="flex flex-col-reverse divide-y divide-y-reverse">
  2. <div>01</div>
  3. <div>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:divide-y-8 to only apply the divide-y-8 utility on hover.

  1. <div class="divide-y divide-gray-400 hover:divide-y-8">
  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:divide-y-8 to apply the divide-y-8 utility at only medium screen sizes and above.

  1. <div class="divide-y divide-gray-400 md:divide-y-8">
  2. <!-- ... -->
  3. </div>

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


Using custom values

Customizing your theme

The divide width scale inherits its values from the borderWidth scale by default, so if you’d like to customize your values for both border width and divide width together, use the theme.borderWidth section of your tailwind.config.js file.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. borderWidth: {
  4. DEFAULT: '1px',
  5. '0': '0',
  6. '2': '2px',
  7. '3': '3px',
  8. '4': '4px',
  9. '6': '6px',
  10. '8': '8px',
  11. }
  12. }
  13. }

To customize only the divide width values, use the theme.divideWidth section of your tailwind.config.js file.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. divideWidth: {
  4. DEFAULT: '1px',
  5. '0': '0',
  6. '2': '2px',
  7. '3': '3px',
  8. '4': '4px',
  9. '6': '6px',
  10. '8': '8px',
  11. }
  12. }
  13. }

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off divide-{x|y}-{width} value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <div class="divide-x-[3px]">
  2. <!-- ... -->
  3. </div>

Learn more about arbitrary value support in the arbitrary values documentation.