Skip to content
Drivn
6 min read

React Separator Component Examples

Copy-paste React Separator examples: horizontal between paragraphs, vertical inside a flex row, styled with custom colour, in a panel, and grouped sections.

A separator is the right control when two stretches of content belong together but need a visible break between them — paragraphs in an article, fields in a form, items in a sidebar, groups in a navigation menu. The Separator component in Drivn is a one-pixel rule that does that job and nothing else. The entire file lives at @/components/ui/separator.tsx, imports only react and the local cn() utility, and renders a single <div role="separator"> with the orientation class merged in.

Every example on this page imports the component from @/components/ui/separator — the path the Drivn CLI installs it under — and passes one or both of its two props: orientation ('horizontal' | 'vertical', default 'horizontal') and className for margin, colour, or thickness overrides. Each snippet is TypeScript because Drivn ships TypeScript-only. The Separator has no client directive, so any of these snippets can render inside a server component without crossing a hydration boundary.

The examples below cover a horizontal divider between paragraphs, a vertical divider inside a flex-row meta strip, a styled Separator with custom colour and thickness, a divider that splits a panel's body from its footer, a stack of grouped sections in a sidebar, and the verbatim component source. The full props table lives on the Separator docs page, and the shadcn/ui comparison sits on Drivn vs shadcn Separator.

A horizontal divider between two paragraphs

The simplest use of a Separator is to drop one between two blocks of content to give them a visible break. The default orientation is 'horizontal', so no prop is needed — the component renders w-full h-px bg-border, which fills the available width and uses the bg-border token so the rule colour follows the theme along with every other border in the project.

Pass className="my-6" (or any margin utility) to add breathing room above and below. Without margin the divider sits flush against its siblings, which is what you want inside a tight list but rarely what you want between paragraphs. The example below pairs the divider with two <p> elements and adds vertical spacing through className — exactly the shape the Separator docs preview uses for the horizontal case.

1import { Separator } from "@/components/ui/separator"
2
3export default function Article() {
4 return (
5 <article>
6 <p>The opening paragraph sets the scene.</p>
7 <Separator className="my-6" />
8 <p>The next paragraph picks up after the break.</p>
9 </article>
10 )
11}

A vertical divider inside a flex row

Pass orientation="vertical" to switch to the vertical rule. The component swaps from w-full h-px bg-border to h-full w-px bg-border, so it now stretches to the height of its parent. That means a vertical Separator needs a sized container — a flex row with a fixed height, a toolbar, a header — or it collapses to zero height because there is no intrinsic content to measure.

The example below is the metadata strip you see under a blog post: author, separator, date, separator, reading time. The wrapper is a flex row with items-center and a h-6 height so the dividers have something to stretch into. The mx-3 on each Separator adds a touch of horizontal breathing room. For a stack of links separated by a slash or chevron rather than a rule, the Breadcrumb component handles the role with built-in spacing.

1import { Separator } from "@/components/ui/separator"
2
3export default function PostMeta() {
4 return (
5 <div className="flex items-center h-6 text-sm text-muted-foreground">
6 <span>Drivn</span>
7 <Separator orientation="vertical" className="mx-3" />
8 <span>May 23, 2026</span>
9 <Separator orientation="vertical" className="mx-3" />
10 <span>4 min read</span>
11 </div>
12 )
13}

A styled Separator with custom colour and thickness

The Separator's default styling is intentional: one pixel, the bg-border token, full width. To make the divider read as a stronger break — at the end of a section, between two unrelated blocks — bump the thickness with className="h-0.5" or swap the colour with className="bg-primary". The cn() utility merges with later-class precedence, so the className you pass wins against the defaults baked into the styles object.

For a softer divider that fades into the page, reach for a translucent token: bg-muted-foreground/20 is the muted text colour at twenty percent opacity. The example below stacks three Separator variants: the default, a thicker primary-coloured rule, and a faded one. Use the same idiom for vertical Separators — w-0.5 for thickness, any bg-* utility for colour. For a labelled divider ("OR" between two auth methods), wrap the Separator and an inline label in a flex row.

1import { Separator } from "@/components/ui/separator"
2
3export default function DividerStyles() {
4 return (
5 <div className="space-y-6">
6 <Separator />
7 <Separator className="h-0.5 bg-primary" />
8 <Separator className="bg-muted-foreground/20" />
9 </div>
10 )
11}

Grouped sidebar sections separated by rules

A sidebar that lists several groups of links benefits from a divider between each group — it makes the grouping visible without an extra heading or extra whitespace alone. Stack the groups and drop a Separator between them with vertical margin. The example below builds a settings sidebar with three groups: account, preferences, and a danger zone.

Because every Separator picks up the bg-border token, the rules stay consistent whether the user is on the light or dark theme — no per-theme override needed. The component file is small enough that the same idiom holds inside a popover, a dropdown menu, or any vertical stack of grouped items. Because the Separator carries role="separator", screen readers announce each group break as a thematic divider rather than skipping it silently. The verbatim component source is reproduced in the next section so the entire surface is visible at once.

1import * as React from "react"
2import { Separator } from "@/components/ui/separator"
3
4const groups = [
5 ["Profile", "Email", "Password"],
6 ["Theme", "Language", "Notifications"],
7 ["Export data", "Delete account"],
8]
9
10export default function SettingsSidebar() {
11 return (
12 <nav className="w-56 space-y-2">
13 {groups.map((items, i) => (
14 <React.Fragment key={i}>
15 {items.map((label) => (
16 <a key={label} href="#" className="block text-sm">
17 {label}
18 </a>
19 ))}
20 {i < groups.length - 1 && <Separator className="my-3" />}
21 </React.Fragment>
22 ))}
23 </nav>
24 )
25}

The verbatim component source

Every detail above maps back to the same eight-line component file. The styles object holds the two orientation rules, the function reads the orientation prop, merges the matching class with whatever className you passed, and renders a div with role="separator". No state, no refs, no hooks, no Radix package. The full source is reproduced below from packages/drivn/src/registry/components/separator.ts so the entire component is visible at once.

That brevity is the reason a Separator can sit in any context — server component, client component, layout, marketing page — without making decisions about hydration or bundle weight on your behalf. After the Drivn CLI writes the file into your project, it is yours: rename it, change the role, drop the className prop, add a decorative flag of your own. The starting point is small enough that any of those edits is a one-line change.

1import * as React from 'react'
2import { cn } from '@/utils/cn'
3
4const styles = {
5 horizontal: 'w-full h-px bg-border',
6 vertical: 'h-full w-px bg-border',
7}
8
9interface SeparatorProps {
10 orientation?: 'horizontal' | 'vertical'
11 className?: string
12}
13
14export function Separator({
15 orientation = 'horizontal',
16 className,
17}: SeparatorProps) {
18 return (
19 <div
20 role="separator"
21 className={cn(styles[orientation], className)}
22 />
23 )
24}
Get started

Install Drivn in one command

Copy the source into your project and own every line. Zero runtime dependencies, pure React + Tailwind.

npx drivn@latest create

Requires Node 18+. Works with npm, pnpm, and yarn.

Enjoying Drivn?
Star the repo on GitHub to follow new component releases.
Star →

Frequently asked questions

The default orientation is horizontal, which renders w-full h-px bg-border — a one-pixel-tall rule that stretches the full width of its parent. Passing orientation="vertical" swaps in h-full w-px bg-border, a one-pixel-wide rule that stretches the full height of its parent. The vertical version needs a sized parent (a flex row with a height, for example) or it collapses to zero.

No. The Separator has no 'use client' directive, no hooks, and no event handlers. It is a plain function that returns a single div. You can render it directly inside server components, layout files, and statically rendered marketing pages without crossing a client boundary or adding to the JavaScript bundle for that route.

Yes. The default thickness is one pixel — h-px on a horizontal rule, w-px on a vertical one. Pass a className with a different size utility (h-0.5, h-1, w-0.5) and cn() will merge it with the defaults using later-class precedence, so the className wins. The same applies to colour, opacity, and margin utilities.

The Separator renders role="separator", which is the ARIA role for a thematic break between content. Assistive technology announces it as a divider rather than skipping it or reading it as content. If you want a purely visual rule that should be ignored, open the component file and either remove the role attribute or change it to role="none".