Divide Utilities in TailwindCSS
? Divide Utilities in Tailwind CSS
Divide utilities in Tailwind are used to add consistent borders between sibling elements (usually in a flex or grid container), without adding borders on the container itself or duplicating borders between elements.
What Divide Utilities Do
They add borders only between direct children inside a container.
Helps to visually separate items horizontally or vertically.
Useful for lists, navbars, card groups, etc.
Key Classes
| Class | Description |
|---|---|
divide-x | Adds vertical borders between horizontal items (left/right) |
divide-x-reverse | Reverses the side of the vertical border (right/left) |
divide-y | Adds horizontal borders between vertical items (top/bottom) |
divide-y-reverse | Reverses the side of the horizontal border (bottom/top) |
Border Color and Width with Divide
You can control the color and width of the divide borders using:
divide-{color}— Sets the color of the dividing border.divide-{width}— Sets the width of the dividing border (e.g.,divide-2for 2px).
Example: Horizontal Dividers Between Items
<div class="flex divide-x divide-gray-300"> <div class="px-4">Item 1</div> <div class="px-4">Item 2</div> <div class="px-4">Item 3</div></div>This creates vertical dividing lines between the flex children.
The
divide-xapplies a left border to every child except the first one.
Example: Vertical Dividers Between Items
<div class="space-y-4 divide-y divide-gray-400"> <div>Item A</div> <div>Item B</div> <div>Item C</div></div>Here,
divide-yadds horizontal lines between the vertical stacked items.space-y-4adds vertical spacing between the items.
Reversing Divide Direction
Sometimes you want the dividing border on the opposite side:
<div class="flex divide-x-reverse divide-red-500"> <div class="px-4">Left Item</div> <div class="px-4">Right Item</div></div>divide-x-reverseshifts the vertical dividing border from left to right side of elements.
Summary
| Utility | Effect |
|---|---|
divide-x | Vertical dividing lines between children |
divide-y | Horizontal dividing lines between children |
divide-x-reverse | Reverse vertical divide side |
divide-y-reverse | Reverse horizontal divide side |
divide-{color} | Color of dividing borders |
divide-{width} | Width of dividing borders |
If you'd like, I can help you create examples combining divide utilities with responsive or hover effects!