Separator
Draws a thin line that divides groups of content.
Brevia Manufacturing
Production, purchasing, quality and sales on one ERP.
Three sites, eleven production lines.
Installation
pnpm dlx shadcn@latest add @silkware/separatorTo copy the component by hand, install its dependencies:
pnpm add react-aria-components cnThen copy the source into components/ui/separator.tsx:
"use client"
import { cn } from "cn"import { Separator as SeparatorPrimitive } from "react-aria-components"
function Separator({ className, orientation = "horizontal", ...props}: React.ComponentProps<typeof SeparatorPrimitive>) { return ( <SeparatorPrimitive data-slot="separator" orientation={orientation} className={cn( "block shrink-0 border-0 bg-border aria-[orientation=horizontal]:h-px aria-[orientation=horizontal]:w-full aria-[orientation=vertical]:w-px aria-[orientation=vertical]:self-stretch [:is(hr)]:h-px [:is(hr)]:w-full", className )} {...props} /> )}
export { Separator }Usage
import { Separator } from "@/components/ui/separator"<Separator className="my-4" />The separator has no margin. Add spacing with className.
Examples
Horizontal
The default. It fills the width of its container.
Brevia Manufacturing
Production, purchasing, quality and sales on one ERP.
Three sites, eleven production lines.
Vertical
orientation="vertical" draws a line that stretches to the height of a flex row. Give the row a height.
Between list items
Put a separator between items, not after the last one.
Accessibility
A separator is not focusable, so it has no keyboard interaction.
React Aria provides:
- The
separatorrole, witharia-orientationset toverticalfor vertical separators. A horizontal separator uses thehrelement.
You provide:
- A choice about meaning. A separator announced by a screen reader says that content changes here. If a line is only decoration, a border on the container does the same job without the announcement.
Guidelines
When to use
- To divide groups of different kinds inside one container: an order header from its delivery details.
- To separate inline items such as a row of links.
When not to use
- To separate every line. Use spacing, which groups without noise.
- To divide sections of a page. Use a heading and space.
- To frame a block. Use a border or a Card.
- In a menu. Use
DropdownMenuSeparatorfrom the Dropdown Menu.
Content
A separator has no text. If the break needs a name, use a heading.
Divide groups that differ in kind.
Tornival
Bergamo
14 December
Don’t draw a line between every row. The lines outweigh the content.
API reference
Separator
Renders an hr, or the element set by elementType, through the React Aria Separator. It accepts every Separator prop.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation? | "horizontal" | "vertical" | "horizontal" | The direction of the line. Vertical separators use a div with the separator role. |
elementType? | string | "hr" | The element to render. Vertical separators render a div. |
className? | string | None | Classes merged after the base classes. |