Skip to the content

Controls and surfaces

separator

A hairline between two pieces of content, horizontal or vertical, with an optional label in the middle.

Display

When to use it

Dividing groups inside a surface or a toolbar. Between page sections use section spacing instead, and inside a list prefer a border on the rows.

See it working

The demonstration the browser checks drive, with the keyboard as well as the pointer. More of it is on the Display page.

Card

Usage

Example figures, this month

62% of the plan used

Stat

Visitors

12,480

+8.2%than last month

Errors

31

−4than last week

Badge, avatar, kbd

SolidSoftOutlineLiveReviewFailed
AKHMRW
CtrlKLoading
or

Alert and empty state

Heads up
Billing moves to the first of the month.

No projects yet

Create one to see it here.

Table

Example rows, not real customers.
NamePlanSeatsStatus
Example StudioTeam12Active
Example BakerySolo1Trial
Example TravelCompany48Active

Add it

npx shadcn@latest add @rivier-ui/separator

The registry is named once in components.json: see Installation.

Example

Import it from @/components/ui/separator.

<Separator />
<Separator>or continue with</Separator>
<div className="flex h-5 items-center gap-3">
  <span>Docs</span>
  <Separator orientation="vertical" />
  <span>Blog</span>
</div>

What it needs

A client component: it uses state, effects or browser behaviour. Packages: radix-ui.

It imports

Source

The whole file. Once copied it is yours: the registry item holds the same text.

src/components/ui/separator.tsx
"use client";
/**
 * @name separator
 * @category ui
 * @description A hairline between two pieces of content, horizontal or vertical, with an optional label in the middle.
 * @when Dividing groups inside a surface or a toolbar. Between page sections use section spacing instead, and inside a list prefer a border on the rows.
 * @example
 * <Separator />
 * <Separator>or continue with</Separator>
 * <div className="flex h-5 items-center gap-3">
 *   <span>Docs</span>
 *   <Separator orientation="vertical" />
 *   <span>Blog</span>
 * </div>
 */
import { Separator as SeparatorPrimitive } from "radix-ui";
import type { ComponentProps } from "react";
import { cn } from "@/lib/cn";

const line =
  "shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:self-stretch";

export type SeparatorProps = ComponentProps<typeof SeparatorPrimitive.Root>;

/**
 * Decorative by default (hidden from assistive technology). Pass `decorative={false}` when the split carries
 * meaning. Children become a centred label; a label is only drawn on a horizontal separator.
 */
export function Separator({ className, orientation = "horizontal", decorative = true, children, asChild, ...props }: SeparatorProps) {
  if (children && orientation === "horizontal" && !asChild) {
    return (
      <div
        data-slot="separator"
        data-orientation="horizontal"
        role={decorative ? undefined : "separator"}
        className={cn("flex w-full items-center gap-3 text-xs text-muted-foreground", className)}
        {...props}
      >
        <SeparatorPrimitive.Root decorative className={cn(line, "min-w-4 flex-1 data-[orientation=horizontal]:w-auto")} />
        <span data-slot="separator-label" className="min-w-0 text-center">
          {children}
        </span>
        <SeparatorPrimitive.Root decorative className={cn(line, "min-w-4 flex-1 data-[orientation=horizontal]:w-auto")} />
      </div>
    );
  }
  return (
    <SeparatorPrimitive.Root
      data-slot="separator"
      orientation={orientation}
      decorative={decorative}
      asChild={asChild}
      className={cn(line, className)}
      {...props}
    >
      {asChild ? children : undefined}
    </SeparatorPrimitive.Root>
  );
}