Skip to content

Divider Properties

Visual separators that create hierarchy and organize content. Supports horizontal/vertical orientations, text, icons, and interactive elements.

Installation

Add Divider to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.

Terminal
npx ck-ui-cli@latest add divider
Adds
Divider.tsxto your CK-UI folder (src/components/ck-ui by default)
Installs
No extra npm packages

First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.

Manual installationInstall the packages and copy the files yourself.

Create or update your Divider component

Copy this code to create your Divider component

/components/ui/Divider.tsx
import * as React from "react";
import { cn } from "@/lib/utils";

// Server-compatible: no hooks or context, so Divider can be rendered from server components.

export type DividerVariant = "line" | "line-text" | "text" | "solid-text" | "content";
export type DividerOrientation = "horizontal" | "vertical";

export interface DividerRootProps extends React.HTMLAttributes<HTMLDivElement> {
    /**
     * - `line`: a plain rule (role="separator").
     * - `line-text` / `content`: children centred between two rules; the rules are decorative and the children stay readable.
     * - `text` / `solid-text`: a label row (no separator role), plain or on a solid background.
     */
    variant?: DividerVariant;
    /** Position of the children for `line-text` / `content`. */
    align?: "left" | "center" | "right";
    /** `vertical` always renders a plain rule (children are not rendered); give it a height, e.g. `className="h-6"`. */
    orientation?: DividerOrientation;
    /** For rules only: hide a purely visual rule from assistive technology instead of exposing it as a separator. */
    decorative?: boolean;
}

const RULE = "bg-border";
// Label text uses muted-foreground (≥4.5:1 in both themes); the old neutral-400/600 measured about 2.5:1.
const LABEL_TEXT = "uppercase size-subheading-xs";

const DividerRoot = React.forwardRef<HTMLDivElement, DividerRootProps>(
    ({ variant = "line", align = "center", orientation = "horizontal", decorative = false, className, children, ...props }, ref) => {
        if (orientation === "vertical" || variant === "line") {
            const semantics: React.HTMLAttributes<HTMLDivElement> = decorative ? { "aria-hidden": true } : { role: "separator", "aria-orientation": orientation };
            return <div ref={ref} {...semantics} className={cn(orientation === "vertical" ? "h-full w-px" : "h-px w-full", RULE, className)} {...props} />;
        }

        if (variant === "line-text" || variant === "content") {
            return (
                <div ref={ref} className={cn("flex w-full items-center gap-2.5", className)} {...props}>
                    {(align === "center" || align === "right") && <div aria-hidden="true" className={cn("h-px flex-1", RULE)} />}
                    <div className={cn("flex-shrink-0 text-muted-foreground", LABEL_TEXT)}>{children}</div>
                    {(align === "center" || align === "left") && <div aria-hidden="true" className={cn("h-px flex-1", RULE)} />}
                </div>
            );
        }

        if (variant === "solid-text") {
            return (
                <div
                    ref={ref}
                    className={cn("flex w-full items-center gap-6 bg-neutral-100 px-5 py-1.5 text-muted-foreground dark:bg-neutral-800", LABEL_TEXT, className)}
                    {...props}
                >
                    {children}
                </div>
            );
        }

        // variant === "text"
        return (
            <div ref={ref} className={cn("flex w-full items-center gap-2 px-2 py-1 text-muted-foreground", LABEL_TEXT, className)} {...props}>
                {children}
            </div>
        );
    }
);
DividerRoot.displayName = "Divider.Root";

export { DividerRoot as Root };

Test Your Component

  • 1. Add the component to a test page
  • 2. Check all props and variants work as expected
  • 3. Verify responsive behavior
  • 4. Test with different content/data
  • 5. Ensure accessibility features work correctly

Different Colors

Apply custom colors to dividers with a background class in className, for example bg-blue-500.

Line Text

Dividers with text and lines on either side, with multiple alignment options.

OR
OR
OR

Text Dividers

Simple text dividers that separate content with meaningful labels.

OR

Solid Text

Distinct text dividers with solid background for stronger visual separation.

Amount & Account

Content

Dividers with interactive elements like buttons for enhanced functionality.

Vertical Orientation

Vertical dividers for separating horizontally aligned content.

API Reference

The Divider component provides a flexible way to create visual separations between content sections.

Divider.Root

Main divider component with support for different orientations and styles. Lines (line and vertical) render role="separator" with aria-orientation. In line-text and content the children stay readable and the lines are decorative; text and solid-text are label rows.

PropTypeDefaultDescription
variant
"line""line-text""text""solid-text""content"
"line"

Visual style of the divider

orientation
"horizontal""vertical"
"horizontal"

vertical always renders a plain line; give it a height with className (e.g. h-6)

align
"center""left""right"
"center"

Position of the children for line-text and content

decorative"boolean""false"

For lines only: hide a purely visual line from assistive technology instead of exposing it as a separator

className"string""undefined"

Additional CSS classes, merged last. Set the line color with a bg-* class.

Used in these blocks

Block families with at least one block built on this component. Each page previews its blocks and lists the components and packages they use.