# 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.

`divider-demo.tsx`:

```tsx
import { Divider } from "@/components/ui/divider";

export default function DividerDemo() {
  return (
    <div className="w-full max-w-sm">
      <Divider>Or continue with</Divider>
    </div>
  );
}
```

## Installation

```bash
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](https://shadcnuikit.com/docs/shadcn-cli). Divider is free and installs without an API key.

### Manual installation

Install the dependencies:

```bash
npm install class-variance-authority
```

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

`components/ui/divider.tsx`:

```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

```tsx
import { Divider } from "@/components/ui/divider";
```

```tsx
<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

```tsx
<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.

`divider-plain.tsx`:

```tsx
import { Divider } from "@/components/ui/divider";

export default function DividerPlain() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-4 text-sm">
      <p>Account settings</p>
      <Divider />
      <p className="text-muted-foreground">Notification settings</p>
    </div>
  );
}
```

### 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.

`divider-align.tsx`:

```tsx
import { Divider } from "@/components/ui/divider";

export default function DividerAlign() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Divider align="start">Start</Divider>
      <Divider>Center</Divider>
      <Divider align="end">End</Divider>
    </div>
  );
}
```

### Variant

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

`divider-variant.tsx`:

```tsx
import { Divider } from "@/components/ui/divider";

export default function DividerVariant() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Divider variant="solid">Solid</Divider>
      <Divider variant="dashed">Dashed</Divider>
      <Divider variant="dotted">Dotted</Divider>
    </div>
  );
}
```

### Orientation

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

`divider-orientation.tsx`:

```tsx
import { Divider } from "@/components/ui/divider";

export default function DividerOrientation() {
  return (
    <div className="flex h-32 items-stretch gap-6 text-sm">
      <span className="self-center">Monthly</span>
      <Divider orientation="vertical" />
      <span className="self-center">Yearly</span>
      <Divider orientation="vertical">or</Divider>
      <span className="self-center">Lifetime</span>
    </div>
  );
}
```

### Icon

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

`divider-icon.tsx`:

```tsx
import { SparklesIcon } from "lucide-react";
import { Divider } from "@/components/ui/divider";

export default function DividerIcon() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Divider aria-hidden="true">
        <SparklesIcon />
      </Divider>
      <Divider>
        <SparklesIcon aria-hidden="true" />
        New features
      </Divider>
    </div>
  );
}
```

### Content

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

`divider-content.tsx`:

```tsx
import { ChevronDownIcon } from "lucide-react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Divider } from "@/components/ui/divider";

export default function DividerContent() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Divider>
        <Badge variant="secondary">Today</Badge>
      </Divider>
      <Divider>
        <Button variant="outline" size="sm" className="rounded-full">
          Show more
          <ChevronDownIcon />
        </Button>
      </Divider>
    </div>
  );
}
```

### Content Class Name

`contentClassName` styles the content wrapper without touching the lines.

`divider-content-class-name.tsx`:

```tsx
import { Divider } from "@/components/ui/divider";

export default function DividerContentClassName() {
  return (
    <div className="w-full max-w-sm">
      <Divider contentClassName="text-foreground text-xs font-medium tracking-wide uppercase">Billing</Divider>
    </div>
  );
}
```

More layouts built with Divider, such as chat date labels and login separators, are on the [Divider components](https://shadcnuikit.com/components/divider) page.

## API Reference

### Divider

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

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `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. |
| `contentClassName` | `string` | | Classes for the content wrapper. |
| `className` | `string` | | Classes for the root. |
| `children` | `ReactNode` | | Content 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.

```tsx
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](https://shadcnuikit.com/components/separator) is the base shadcn/ui version of the same idea.
- Steps or events on a line with markers. Use [Timeline](https://shadcnuikit.com/components/timeline) or [Stepper](https://shadcnuikit.com/components/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**

- Markdown: [/docs/components/divider.md](https://shadcnuikit.com/docs/components/divider.md)
- Variants: [Divider components](https://shadcnuikit.com/components/divider), 15 free examples
- Install: `npx shadcn@latest add @shadcnuikit/divider1`
- MCP: call `get_item_code` with `divider1` from the [MCP Server](https://shadcnuikit.com/docs/mcp-server)
- Full index for agents: [llms.txt](https://shadcnuikit.com/llms.txt)

Source: https://shadcnuikit.com/docs/components/divider
More from Shadcn UI Kit: [llms.txt](https://shadcnuikit.com/llms.txt)