Divide Width

Tailwind CSS version

v1.3.0+

Utilities for controlling the border width between elements.

Class reference

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

Add borders between horizontal children

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

Divide Width - 图1

  1. <div class="grid grid-cols-3 divide-x divide-gray-400">
  2. <div class="text-center">1</div>
  3. <div class="text-center">2</div>
  4. <div class="text-center">3</div>
  5. </div>

Add borders between stacked children

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

Divide Width - 图2

  1. <div class="divide-y divide-gray-400">
  2. <div class="text-center py-2">1</div>
  3. <div class="text-center py-2">2</div>
  4. <div class="text-center py-2">3</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 divide-gray-400">
  2. <div class="text-center py-2">1</div>
  3. <div class="text-center py-2">2</div>
  4. <div class="text-center py-2">3</div>
  5. </div>

Responsive

To control the borders between elements at a specific breakpoint, add a {screen}: prefix to any existing divide utility. For example, adding the class md:divide-x-8 to an element would apply the divide-x-8 utility at medium screen sizes and above.

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Divide Width - 图4

all

Divide Width - 图5

sm

Divide Width - 图6

md

Divide Width - 图7

lg

Divide Width - 图8

xl

  1. <div class="divide-y sm:divide-y-2 md:divide-y-4 lg:divide-y-8 xl:divide-y-0 divide-gray-400">
  2. <div class="text-center py-2">1</div>
  3. <div class="text-center py-2">2</div>
  4. <div class="text-center py-2">3</div>
  5. </div>

1

2

3


Customizing

Divide width scale

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.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. borderWidth: {
  5. default: '1px',
  6. '0': '0',
  7. '2': '2px',
  8. + '3': '3px',
  9. '4': '4px',
  10. + '6': '6px',
  11. - '8': '8px',
  12. }
  13. }
  14. }

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

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. divideWidth: {
  5. default: '1px',
  6. '0': '0',
  7. '2': '2px',
  8. + '3': '3px',
  9. '4': '4px',
  10. + '6': '6px',
  11. - '8': '8px',
  12. }
  13. }
  14. }

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

Responsive and pseudo-class variants

By default, only responsive variants are generated for divide width utilities.

You can control which variants are generated for the divide width utilities by modifying the divideWidth 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. - divideWidth: ['responsive'],
  6. + divideWidth: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

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

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

← Border Style   Divide Color →