Menu

Components

Separator

A line that divides content into parts: sections of a page, groups in a menu, items in a row. It can carry a label.

Introduction

Separator is a thin line between things: two sections of a page, the groups of a menu, the links in a row. It says that what is on one side is not part of what is on the other, without the weight of a box.

  • Horizontal, between things above and below, or vertical, between things side by side, where it takes the height of its row.
  • Four kinds of line: solid, dashed, dotted, and one that fades out at both ends. Three thicknesses and three strengths, all following the theme.
  • A label goes in the middle of the line, such as "or" between two ways to sign in, and can sit at the start or the end.
  • A plain separator is a real one for assistive technology, which announces the break. If it is only for looks, mark it isDecorative and it is skipped.
  • It has no client code, so it works in Server Components.

A separator does not add space by itself. Put the space around it with a class such as my-4. For a heading above a section, see Heading.

Installation

centerUI has no CLI or registry yet: components are copied into your project.

# bun
bun add tailwind-variants tailwind-merge clsx

# pnpm
pnpm add tailwind-variants tailwind-merge clsx

# npm
npm install tailwind-variants tailwind-merge clsx

Manual installation

Copy these files into your project and keep the paths, or adjust the imports.

1. Add the styles

src/types/separator-styles.tsShow code
import { tv } from "tailwind-variants";

// Styles for Separator. A separator is a line, drawn with a border (solid,
// dashed or dotted) or with a gradient (fade), horizontal or vertical. With a
// label the line is drawn on both sides of the text.
//
// The class names are written out in full: Tailwind finds a class by reading
// the source, so one built from pieces (`border-t-${width}`) would never be
// generated.
export const separatorStyles = tv({
  slots: {
    line: "m-0 shrink-0 border-0 p-0",
    group: "flex items-center gap-3 text-muted-fg",
    label: "shrink-0 text-xs font-medium",
  },
  variants: {
    orientation: {
      horizontal: { line: "w-full", group: "w-full flex-row" },
      vertical: {
        line: "h-full min-h-4 self-stretch",
        group: "h-full min-h-16 flex-col self-stretch",
      },
    },
    variant: {
      solid: {},
      dashed: {},
      dotted: {},
      fade: {},
    },
    thickness: { thin: {}, md: {}, thick: {} },
    tone: { muted: {}, default: {}, strong: {} },
  },
  compoundVariants: [
    // Solid, horizontal: a border on top.
    {
      variant: "solid",
      orientation: "horizontal",
      thickness: "thin",
      class: { line: "h-0 border-t border-solid" },
    },
    {
      variant: "solid",
      orientation: "horizontal",
      thickness: "md",
      class: { line: "h-0 border-t-2 border-solid" },
    },
    {
      variant: "solid",
      orientation: "horizontal",
      thickness: "thick",
      class: { line: "h-0 border-t-4 border-solid" },
    },
    // Dashed
    {
      variant: "dashed",
      orientation: "horizontal",
      thickness: "thin",
      class: { line: "h-0 border-t border-dashed" },
    },
    {
      variant: "dashed",
      orientation: "horizontal",
      thickness: "md",
      class: { line: "h-0 border-t-2 border-dashed" },
    },
    {
      variant: "dashed",
      orientation: "horizontal",
      thickness: "thick",
      class: { line: "h-0 border-t-4 border-dashed" },
    },
    // Dotted
    {
      variant: "dotted",
      orientation: "horizontal",
      thickness: "thin",
      class: { line: "h-0 border-t border-dotted" },
    },
    {
      variant: "dotted",
      orientation: "horizontal",
      thickness: "md",
      class: { line: "h-0 border-t-2 border-dotted" },
    },
    {
      variant: "dotted",
      orientation: "horizontal",
      thickness: "thick",
      class: { line: "h-0 border-t-4 border-dotted" },
    },
    // Solid, vertical: a border on the left.
    {
      variant: "solid",
      orientation: "vertical",
      thickness: "thin",
      class: { line: "w-0 border-l border-solid" },
    },
    {
      variant: "solid",
      orientation: "vertical",
      thickness: "md",
      class: { line: "w-0 border-l-2 border-solid" },
    },
    {
      variant: "solid",
      orientation: "vertical",
      thickness: "thick",
      class: { line: "w-0 border-l-4 border-solid" },
    },
    {
      variant: "dashed",
      orientation: "vertical",
      thickness: "thin",
      class: { line: "w-0 border-l border-dashed" },
    },
    {
      variant: "dashed",
      orientation: "vertical",
      thickness: "md",
      class: { line: "w-0 border-l-2 border-dashed" },
    },
    {
      variant: "dashed",
      orientation: "vertical",
      thickness: "thick",
      class: { line: "w-0 border-l-4 border-dashed" },
    },
    {
      variant: "dotted",
      orientation: "vertical",
      thickness: "thin",
      class: { line: "w-0 border-l border-dotted" },
    },
    {
      variant: "dotted",
      orientation: "vertical",
      thickness: "md",
      class: { line: "w-0 border-l-2 border-dotted" },
    },
    {
      variant: "dotted",
      orientation: "vertical",
      thickness: "thick",
      class: { line: "w-0 border-l-4 border-dotted" },
    },
    // The color of a line drawn with a border.
    {
      variant: ["solid", "dashed", "dotted"],
      tone: "muted",
      class: { line: "border-border/50" },
    },
    {
      variant: ["solid", "dashed", "dotted"],
      tone: "default",
      class: { line: "border-border" },
    },
    {
      variant: ["solid", "dashed", "dotted"],
      tone: "strong",
      class: { line: "border-fg/30" },
    },
    // A line that fades out at both ends.
    {
      variant: "fade",
      orientation: "horizontal",
      thickness: "thin",
      class: { line: "h-px bg-linear-to-r from-transparent to-transparent" },
    },
    {
      variant: "fade",
      orientation: "horizontal",
      thickness: "md",
      class: { line: "h-0.5 bg-linear-to-r from-transparent to-transparent" },
    },
    {
      variant: "fade",
      orientation: "horizontal",
      thickness: "thick",
      class: { line: "h-1 bg-linear-to-r from-transparent to-transparent" },
    },
    {
      variant: "fade",
      orientation: "vertical",
      thickness: "thin",
      class: { line: "w-px bg-linear-to-b from-transparent to-transparent" },
    },
    {
      variant: "fade",
      orientation: "vertical",
      thickness: "md",
      class: { line: "w-0.5 bg-linear-to-b from-transparent to-transparent" },
    },
    {
      variant: "fade",
      orientation: "vertical",
      thickness: "thick",
      class: { line: "w-1 bg-linear-to-b from-transparent to-transparent" },
    },
    { variant: "fade", tone: "muted", class: { line: "via-border/50" } },
    { variant: "fade", tone: "default", class: { line: "via-border" } },
    { variant: "fade", tone: "strong", class: { line: "via-fg/30" } },
  ],
  defaultVariants: {
    orientation: "horizontal",
    variant: "solid",
    thickness: "thin",
    tone: "default",
  },
});

2. Add the Separator file

src/components/ui/separator/separator.tsxShow code
import type { ReactNode } from "react";
import { cn } from "@/lib/cn";
import { separatorStyles } from "@/types/separator-styles";

export interface SeparatorProps {
  /**
   * Text in the middle of the line, such as "or". A separator with a label is
   * decorative: the text is read, and the lines are not.
   */
  children?: ReactNode;
  /** A horizontal rule between things above and below, or a vertical one between things side by side. */
  orientation?: "horizontal" | "vertical";
  /** The line: solid, dashed, dotted, or a line that fades out at both ends. */
  variant?: "solid" | "dashed" | "dotted" | "fade";
  /** How thick the line is: 1, 2 or 4 pixels. */
  thickness?: "thin" | "md" | "thick";
  /** How strong the line is against the background. */
  tone?: "muted" | "default" | "strong";
  /** With a label: where the text sits on the line. Defaults to the middle. */
  labelAlign?: "start" | "center" | "end";
  /**
   * The line is only for looks and is not a break in the content, so assistive
   * technology skips it. Leave it off when it really divides two parts of the
   * page or of a menu.
   */
  isDecorative?: boolean;
  className?: string;
}

/**
 * A line that divides content into parts: sections of a page, groups in a
 * menu, items in a toolbar. It is a real separator for assistive technology,
 * unless you say it is only decoration, and it can carry a label, such as the
 * "or" between two ways to sign in.
 *
 * It has no client code, so it works in Server Components. A vertical
 * separator takes the height of the row it is in.
 *
 * @example
 * <Separator />
 * <Separator>or continue with</Separator>
 * <div className="flex h-5 items-center gap-3">Docs <Separator orientation="vertical" /> Blog</div>
 */
export function Separator({
  children,
  orientation = "horizontal",
  variant,
  thickness,
  tone,
  labelAlign = "center",
  isDecorative = false,
  className,
}: SeparatorProps) {
  const styles = separatorStyles({ orientation, variant, thickness, tone });
  const hasLabel =
    children !== undefined && children !== null && children !== false;

  if (hasLabel) {
    // The first line is short when the label is at the start, and the last
    // when it is at the end.
    const short = orientation === "horizontal" ? "w-6" : "h-6";
    return (
      <div role="none" className={cn(styles.group(), className)}>
        <span
          aria-hidden="true"
          className={cn(
            styles.line(),
            labelAlign === "start" ? `${short} flex-none` : "flex-1",
          )}
        />
        <span className={styles.label()}>{children}</span>
        <span
          aria-hidden="true"
          className={cn(
            styles.line(),
            labelAlign === "end" ? `${short} flex-none` : "flex-1",
          )}
        />
      </div>
    );
  }

  if (orientation === "vertical") {
    // An hr is always horizontal, so a vertical separator is a div with the role.
    return isDecorative ? (
      <div role="none" className={cn(styles.line(), className)} />
    ) : (
      // biome-ignore lint/a11y/useSemanticElements: an hr cannot be vertical
      // biome-ignore lint/a11y/useFocusableInteractive: a separator that only divides is not a focusable widget (that is the slider kind)
      <div
        // biome-ignore lint/a11y/useAriaPropsForRole: aria-valuenow is for a focusable separator; this one is static
        role="separator"
        aria-orientation="vertical"
        className={cn(styles.line(), className)}
      />
    );
  }

  return (
    <hr
      role={isDecorative ? "none" : undefined}
      className={cn(styles.line(), className)}
    />
  );
}

3. Use it

import { Separator } from "@/components/ui/separator/separator";

Anatomy

A line, and optionally a label with a line on each side.

<Separator />
<Separator variant="dashed">or</Separator>
<div className="flex h-5 items-center gap-3">Docs <Separator orientation="vertical" /> Blog</div>
PartRendered asNotes
Linehr, or a div for a vertical oneA real separator for assistive technology, unless isDecorative is set.
LabelspanText in the middle of the line, with a line on each side. The labelled separator is decorative and the text is read.

Examples

Usage

Account

Manage your profile and settings.

Read the docs, or contact support.

Orientation

Vertical goes between things side by side. It takes the height of the row it is in, so give the row a height.

DocsBlogChangelog

Variants

Solid is the default. Dashed and dotted are lighter in feel. Fade dissolves at both ends, for a soft break between big sections.


Thickness

1, 2 or 4 pixels, in every kind of line.


Tone

How strong the line is against the background: muted for a hint, strong for a clear break.

With a label

Text in the middle of the line, with a line on each side, such as the “or” between two ways to sign in. The text is read, and the lines are not.

or continue with
Step 2
Later this week

Label position

The label sits in the middle, or at the start or the end of the line.

Start
Center
End

Vertical with a label

A vertical separator can have a label too, in the middle of a column.

Sign in with email
or
Sign in with a provider

In a menu

Between groups of items, with a little space on each side.

Decorative

A line that is only for looks, not a break in the content, is marked isDecorative, and assistive technology skips it. Otherwise it is announced as a separator.

Component API

Separator takes the props below.

PropTypeDefault
childrenReactNode-
orientation"horizontal" | "vertical""horizontal"
variant"solid" | "dashed" | "dotted" | "fade""solid"
thickness"thin" | "md" | "thick""thin"
tone"muted" | "default" | "strong""default"
labelAlign"start" | "center" | "end""center"
isDecorativebooleanfalse
classNamestring-