Divider
A thin rule that separates content, optionally with a centered label. Smart by default: it collapses when it would be orphaned, so a dynamic list never leaves a rule at the edge or over an empty state.
Installation#
Usage#
import { Divider } from "@/components/ui/divider"
export function Example() {
return (
<div>
<p>Above</p>
<Divider />
<p>Below</p>
</div>
)
}Smart by default#
A divider only earns its space when it actually separates two things. By default it auto-collapses when it would be orphaned: at the very start or end of a group, doubled against another divider, or stranded next to content that filtered or rendered away. So you can drop a <Divider /> after every row without guarding it: a dynamic list never shows a rule at the edge, and the empty state stays clean. Toggle the rows below, then flip static to switch the guarantee off and watch the orphaned trailing rule reappear.
The contract is the idiomatic one: absent content renders null (or carries the hidden attribute), so a neighbour that is gone is gone from the layout too. Where the dividers are the content themselves (a showcase), or a leading or trailing rule is intentional, pass static to opt out.
Variants#
Four stroke styles. solid, dashed, and dotted ride the border-* utilities; gradient fades a hairline out at both ends for a softer separation between large surfaces. The gallery pins each rule with static so every stroke shows at once; on its own a Divider is smart by default.
With label#
Pass children to render a centered label between two lines, ideal for an “OR” separator in auth forms. The label is text or an icon; the flanking lines are aria-hidden so the a11y tree still exposes exactly one separator.
Label position#
labelPosition sets where the label sits. start and end drop the line on that side so the label hugs the edge.
Vertical#
Set orientation="vertical" to separate inline content. The divider stretches to the height of its container, so place it in a flex row. Vertical dividers don't take a label.
API reference#
Divider
A plain rule is Radix Separator.Root; with a label it is a <div role="separator"> wrapping two aria-hidden lines and the label. Forwards all native <div> props and accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "solid" | "dashed" | "dotted" | "gradient" | "solid" | Stroke style. gradient drops the border and paints a hairline that fades out at both ends. |
| orientation | "horizontal" | "vertical" | "horizontal" | A vertical divider stretches to its container's height and ignores children. |
| children | React.ReactNode | - | A label (text or icon) set between two lines. Horizontal only. |
| labelPosition | "start" | "center" | "end" | "center" | Where the label sits; start and end drop the line on that side. Ignored without children. |
| decorative | boolean | false | Purely visual: the rule takes role="none" and leaves the accessibility tree. |
| static | boolean | false | Opt out of the smart auto-collapse, so the rule paints even at the edge of its group or next to another divider. |
| Data attribute | Description |
|---|---|
| data-orientation | "horizontal" or "vertical", set by Radix on the plain (unlabeled) rule. |
| data-smart | Present unless static; opts the divider into the collapse rules in globals.css. |