Separator
A 1 pixel line between two parts of a view: sections of a panel, items in a toolbar, the two halves of a sign-in form. Give it text and the text sits in the line. For a frame around one subject use the card.
Install
npx shadcn@latest add https://thrumui.dev/r/separator.jsonAdds components/ui/separator.tsx and installs @base-ui/react@1.9.0. Nothing else in your project changes.
import { Separator } from "@/components/ui/separator";Props
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | Default "horizontal" | The direction of the line. A horizontal line fills the width. A vertical one takes the height of its flex row. |
decorative | boolean | Default true | A decorative line has no role and screen readers skip it. Set false where the line marks a real change of subject: it then has the separator role. It has no effect on a labelled separator. |
align | "center" | "start" | Default "center" | Where the label sits: in the middle, or near the start, after a 16 pixel piece of the line. |
children | ReactNode | – | A label set into the line, in 12 pixel muted text. A long one wraps. |
className | string | – | Extra classes, merged last. my-4 adds room above and below. |
...props | ComponentProps<"div"> | – | Every other div attribute is passed through. |
Motion and sound
Motion
- The separator does not move.
Sound
Silent. This component makes no sound.
Accessibility
- By default the line is decoration: it has role none, and a screen reader does not stop on it.
- With decorative set to false it has the separator role and its orientation, from the headless base.
- A labelled separator is a plain element with its text. The text is read in place, like any other, and the two lines beside it are hidden.
- The line is the theme's border colour, the same weight as a card's frame. It is never the only sign that two things differ.
Source
"use client";
import { Separator as SeparatorPrimitive } from "@base-ui/react/separator";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
export type SeparatorProps = ComponentProps<"div"> & {
/** The direction of the line. A vertical one takes the height of its row. */
orientation?: "horizontal" | "vertical";
/** A decorative line is hidden from screen readers. Set `false` where the line marks a real change of subject. */
decorative?: boolean;
/** Where the label sits on the line, when there is one. */
align?: "center" | "start";
};
const LINE = "shrink-0 bg-foreground/20";
/**
* A 1 pixel line between two parts of a view. With children it becomes a label set into the line.
* A vertical separator takes the height of its row, so put it in a flex container.
*/
export function Separator({ orientation = "horizontal", decorative = true, align = "center", className, children, ...props }: SeparatorProps) {
const vertical = orientation === "vertical";
if (children === undefined || children === null || children === false) {
return (
<SeparatorPrimitive
data-slot="separator"
orientation={orientation}
// A decorative line gives up the separator role the primitive sets.
{...(decorative ? { role: "none", "aria-orientation": undefined } : {})}
className={cn(LINE, vertical ? "w-px self-stretch" : "h-px w-full", className)}
{...props}
/>
);
}
// With a label the text is the content: a reader meets it in place, and the two lines are decoration.
const line = cn(LINE, "flex-1", vertical ? "min-h-4 w-px" : "h-px min-w-4");
return (
<div
data-slot="separator"
data-orientation={orientation}
className={cn("flex items-center gap-3 text-xs leading-4 text-muted-foreground", vertical ? "flex-col self-stretch" : "w-full", className)}
{...props}
>
<span aria-hidden="true" className={cn(line, align === "start" && (vertical ? "max-h-4" : "max-w-4"))} />
<span data-slot="separator-label" className="min-w-0 text-center">
{children}
</span>
<span aria-hidden="true" className={line} />
</div>
);
}Files and dependencies
- Adds
components/ui/separator.tsx- Packages
@base-ui/react@1.9.0- Brings along
- Nothing
Changelog
- 1.0.0 · 2026-12-03First release.