View as Markdown

Shadcn Divider

A line that splits content into groups, with optional content placed on it. Put text, an icon, a badge or a button at the start, center or end of the line, run it horizontally or vertically, and pick a solid, dashed or dotted style. It is a single component with no JavaScript, so it works in server components.

Or continue with

Installation

npx shadcn@latest add @shadcnuikit/divider1

This adds components/ui/divider.tsx and a demo file. Set up the registry once as described in Shadcn CLI. Divider is free and installs without an API key.

Manual installation

Install the dependencies:

npm install class-variance-authority

Copy the source into components/ui/divider.tsx:

components/ui/divider.tsx
import * as React from "react";import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const dividerLineVariants = cva("border-border flex-1", { variants: { orientation: { horizontal: "h-0 min-w-4 border-t", vertical: "min-h-4 w-0 border-s", }, variant: { solid: "border-solid", dashed: "border-dashed", dotted: "border-dotted", }, }, compoundVariants: [ { orientation: "horizontal", variant: "dotted", className: "border-t-2" }, { orientation: "vertical", variant: "dotted", className: "border-s-2" }, ], defaultVariants: { orientation: "horizontal", variant: "solid", },});
type DividerProps = React.ComponentProps<"div"> & VariantProps<typeof dividerLineVariants> & { align?: "start" | "center" | "end"; contentClassName?: string; };
function Divider({ align = "center", orientation = "horizontal", variant, className, contentClassName, children, ...props}: DividerProps) { const line = dividerLineVariants({ orientation, variant }); const vertical = orientation === "vertical";
if (!children) { return ( <div role="separator" aria-orientation={vertical ? "vertical" : "horizontal"} data-slot="divider" data-orientation={orientation} className={cn(vertical ? "flex self-stretch" : "flex w-full", className)} {...props} > <span aria-hidden="true" className={line} /> </div> ); }
return ( <div data-slot="divider" data-orientation={orientation} data-align={align} className={cn( "flex items-center", vertical ? "flex-col gap-2 self-stretch" : "w-full gap-3", className, )} {...props} > {align !== "start" && <span aria-hidden="true" className={line} />} <div data-slot="divider-content" className={cn( "text-muted-foreground flex shrink-0 items-center gap-1.5 text-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", vertical && "flex-col", contentClassName, )} > {children} </div> {align !== "end" && <span aria-hidden="true" className={line} />} </div> );}
export { Divider, dividerLineVariants };export type { DividerProps };

Usage

import { Divider } from "@/components/ui/divider";
<Divider />
<Divider>Or continue with</Divider>

Without children, Divider renders a plain line with role="separator". With children, it renders a line on each side of the content.

Vertical

<div className="flex h-12 items-stretch gap-4">
  <span>Monthly</span>
  <Divider orientation="vertical" />
  <span>Yearly</span>
</div>

A vertical divider stretches to the height of its flex parent with self-stretch, so the parent needs a height or other tall children.

Examples

Plain

Without children, the divider is a single line.

Account settings

Notification settings

Align

align places the content at the start, center or end of the line. Start and end follow the text direction, so they flip in right to left layouts.

Start
Center
End

Variant

variant sets the line style: solid, dashed or dotted.

Solid
Dashed
Dotted

Orientation

orientation="vertical" runs the line top to bottom, with or without content.

MonthlyYearly
or
Lifetime

Icon

Icons inside the content get size-4 unless you set a size. Hide an icon-only divider from screen readers with aria-hidden.

New features

Content

Any element works as content, such as a badge or a button.

Today

Content Class Name

contentClassName styles the content wrapper without touching the lines.

Billing

More layouts built with Divider, such as chat date labels and login separators, are on the Divider components page.

API Reference

Divider

The line, with optional content. Takes every prop of a div.

PropTypeDefaultDescription
orientation"horizontal", "vertical""horizontal"Which way the line runs.
variant"solid", "dashed", "dotted""solid"The line style. Dotted lines are 2px thick so the dots stay visible.
align"start", "center", "end""center"Where the content sits on the line. Only used with children.
contentClassNamestringClasses for the content wrapper.
classNamestringClasses for the root.
childrenReactNodeContent shown on the line. Without it, Divider renders a plain separator.

The root has data-slot="divider", data-orientation and, with children, data-align. The content wrapper has data-slot="divider-content".

dividerLineVariants

The class names for the line itself, built with cva. Use it to style another element like a divider line.

import { dividerLineVariants } from "@/components/ui/divider";

<span className={dividerLineVariants({ orientation: "horizontal", variant: "dashed" })} />;

Accessibility

  • A divider without children has role="separator" and aria-orientation, so screen readers announce it as a separator.
  • A divider with children is a plain element and its content is read as normal text. The lines are always aria-hidden.
  • Add aria-hidden="true" to a divider that only holds a decorative icon.
  • Divider is not focusable and has no keyboard interaction.

For AI Agents

When to use

  • Splitting a form or a card into groups, such as "Or continue with" between social and email login.
  • Labelled section breaks in lists and feeds, such as a date label in a chat.
  • A vertical line between inline items, such as toolbar groups or pricing options.

When not to use

  • A plain 1px line with no content and no style options. Separator is the base shadcn/ui version of the same idea.
  • Steps or events on a line with markers. Use Timeline or Stepper.
  • Headings that need to be in the document outline. Use a real heading element, not divider text.

Agent notes

  • Import from @/components/ui/divider. The exports are Divider, dividerLineVariants and the DividerProps type.
  • Divider has no "use client" and no hooks, so it renders in server components.
  • Line color comes from the border-border theme token. There is no prop for line classes. The lines are the root's direct span children, so recolor them with a theme token, such as className="[&>span]:border-primary", not a hard-coded color.
  • Style text and icons with contentClassName. className goes on the root, not the content.
  • A vertical divider needs a parent with a height. In a flex row it stretches with self-stretch.

Resources