Skip to content

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/separator

To copy the component by hand, install its dependencies:

pnpm add react-aria-components cn

Then copy the source into components/ui/separator.tsx:

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.

OrdersSuppliersSites

Between list items

Put a separator between items, not after the last one.

ProductionWork orders and line schedules
PurchasingOrders, suppliers and deliveries
QualityInspections and corrective actions

Accessibility

A separator is not focusable, so it has no keyboard interaction.

React Aria provides:

  • The separator role, with aria-orientation set to vertical for vertical separators. A horizontal separator uses the hr element.

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 DropdownMenuSeparator from the Dropdown Menu.

Content

A separator has no text. If the break needs a name, use a heading.

PO-2041Tornival, Bergamo
Delivery14 December, gate 2
Do

Divide groups that differ in kind.

PO-2041TornivalBergamo14 December
Don’t

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.

PropTypeDefaultDescription
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?stringNoneClasses merged after the base classes.