Divider
A horizontal rule with an optional centered label, spacing steps and a line-less mode.
A rule between two groups of content, with an optional label in its centre. Use it for the date line in a message list or between sections of a dense panel.
It is built on Radix Separator in React and Reka UI Separator in Vue. The primitive sets the role and the orientation. The look comes from dividerVariants.
newt-dividerimport { Divider } from "@/registry/bases/newt/ui/divider"
export default function DividerDemo() {
return (
<div className="w-full max-w-sm text-sm text-newt-text-secondary">
<Divider>SECTION LABEL</Divider>
<Divider spacing="sm" />
<Divider spacing="lg" line={false}>
SPACING ONLY
</Divider>
<p className="m-0">Above a small separator</p>
<Divider spacing="small" />
<p className="m-0">Between a small and a large separator</p>
<Divider spacing="large" />
<p className="m-0">Below a large separator</p>
</div>
)
}<script setup lang="ts">
import { Divider } from "~~/registry/bases/newt/ui/divider"
</script>
<template>
<div class="w-full max-w-sm text-sm text-newt-text-secondary">
<Divider>SECTION LABEL</Divider>
<Divider spacing="sm" />
<Divider spacing="lg" :line="false">SPACING ONLY</Divider>
<p class="m-0">Above a small separator</p>
<Divider spacing="small" />
<p class="m-0">Between a small and a large separator</p>
<Divider spacing="large" />
<p class="m-0">Below a large separator</p>
</div>
</template>A Components V2 separator has two steps. Use spacing="small" for 4px and spacing="large" for 8px. The sm, md and lg steps still work for other layouts.
Installation
npx newtui@latest add dividernpx shadcn@latest add @newtui/dividernpx shadcn-vue@latest add @newtui/dividerpnpm dlx newtui@latest add dividerpnpm dlx shadcn@latest add @newtui/dividerpnpm dlx shadcn-vue@latest add @newtui/divideryarn dlx newtui@latest add divideryarn dlx shadcn@latest add @newtui/divideryarn dlx shadcn-vue@latest add @newtui/dividerbunx newtui@latest add dividerbunx shadcn@latest add @newtui/dividerbunx shadcn-vue@latest add @newtui/dividerdeno run -A npm:newtui@latest add dividerdeno run -A npm:shadcn@latest add @newtui/dividerdeno run -A npm:shadcn-vue@latest add @newtui/dividervlx newtui@latest add dividervlx shadcn@latest add @newtui/dividervlx shadcn-vue@latest add @newtui/dividervp dlx newtui@latest add dividervp dlx shadcn@latest add @newtui/dividervp dlx shadcn-vue@latest add @newtui/dividernubx newtui@latest add dividernubx shadcn@latest add @newtui/dividernubx shadcn-vue@latest add @newtui/dividernlx newtui@latest add dividernlx shadcn@latest add @newtui/dividernlx shadcn-vue@latest add @newtui/dividerupx newtui@latest add dividerupx shadcn@latest add @newtui/dividerupx shadcn-vue@latest add @newtui/divider- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install class-variance-authority radix-uipnpm add class-variance-authority radix-uiyarn add class-variance-authority radix-uibun add class-variance-authority radix-uideno add npm:class-variance-authority npm:radix-uivlt install class-variance-authority radix-uivp add class-variance-authority radix-uinub add class-variance-authority radix-uini class-variance-authority radix-uiupm add class-variance-authority radix-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
npm install class-variance-authority reka-uipnpm add class-variance-authority reka-uiyarn add class-variance-authority reka-uibun add class-variance-authority reka-uideno add npm:class-variance-authority npm:reka-uivlt install class-variance-authority reka-uivp add class-variance-authority reka-uinub add class-variance-authority reka-uini class-variance-authority reka-uiupm add class-variance-authority reka-ui- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
"use client"
import { cva, type VariantProps } from "class-variance-authority"
import { Separator as SeparatorPrimitive } from "radix-ui"
import * as React from "react"
import { cn } from "@/lib/utils"
const dividerVariants = cva(
"flex items-center gap-3 text-xs font-semibold text-newt-text-muted data-[orientation=vertical]:flex-col data-[orientation=vertical]:self-stretch",
{
variants: {
/*
* Spacing steps, for stacking dividers inside dense containers.
* `small` and `large` are the two steps of a Components V2 separator.
*/
spacing: {
small:
"my-1 data-[orientation=vertical]:mx-1 data-[orientation=vertical]:my-0",
large:
"my-2 data-[orientation=vertical]:mx-2 data-[orientation=vertical]:my-0",
sm: "my-1 data-[orientation=vertical]:mx-1 data-[orientation=vertical]:my-0",
md: "my-4 data-[orientation=vertical]:mx-4 data-[orientation=vertical]:my-0",
lg: "my-6 data-[orientation=vertical]:mx-6 data-[orientation=vertical]:my-0",
},
/* Pure spacing: keeps the gap, drops the rules around the label. */
line: {
true: "before:h-px before:flex-1 before:bg-newt-border before:content-[''] after:h-px after:flex-1 after:bg-newt-border after:content-[''] data-[orientation=vertical]:before:h-auto data-[orientation=vertical]:before:w-px data-[orientation=vertical]:after:h-auto data-[orientation=vertical]:after:w-px",
false: "",
},
},
defaultVariants: {
spacing: "md",
line: true,
},
}
)
export interface DividerProps
extends
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>,
VariantProps<typeof dividerVariants> {}
/*
* Radix owns the semantics: `role="separator"`, `aria-orientation` when it is
* vertical, and no role at all when it is `decorative`. Only the look is
* newt/ui's.
*/
const Divider = React.forwardRef<
React.ComponentRef<typeof SeparatorPrimitive.Root>,
DividerProps
>(({ className, spacing, line, ...props }, ref) => (
<SeparatorPrimitive.Root
ref={ref}
className={cn(dividerVariants({ spacing, line }), className)}
{...props}
/>
))
Divider.displayName = "Divider"
export { Divider, dividerVariants }<script setup lang="ts">
import { Separator, type SeparatorProps } from "reka-ui"
import { computed, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
import { dividerVariants, type DividerVariants } from "."
/*
* Reka owns the semantics: `role="separator"`, `aria-orientation` when it is
* vertical, and no role at all when it is `decorative`. Only the look is
* newt/ui's.
*/
const props = withDefaults(
defineProps<
SeparatorProps & {
class?: HTMLAttributes["class"]
spacing?: DividerVariants["spacing"]
line?: boolean
}
>(),
{ line: true }
)
const delegated = computed(() => {
const { class: _class, spacing: _spacing, line: _line, ...rest } = props
return rest
})
</script>
<template>
<Separator
v-bind="delegated"
:class="
cn(
dividerVariants({ spacing: props.spacing, line: props.line }),
props.class
)
"
>
<slot />
</Separator>
</template>import { cva, type VariantProps } from "class-variance-authority"
export { default as Divider } from "./Divider.vue"
export const dividerVariants = cva(
"flex items-center gap-3 text-xs font-semibold text-newt-text-muted data-[orientation=vertical]:flex-col data-[orientation=vertical]:self-stretch",
{
variants: {
/*
* Spacing steps, for stacking dividers inside dense containers.
* `small` and `large` are the two steps of a Components V2 separator.
*/
spacing: {
small:
"my-1 data-[orientation=vertical]:mx-1 data-[orientation=vertical]:my-0",
large:
"my-2 data-[orientation=vertical]:mx-2 data-[orientation=vertical]:my-0",
sm: "my-1 data-[orientation=vertical]:mx-1 data-[orientation=vertical]:my-0",
md: "my-4 data-[orientation=vertical]:mx-4 data-[orientation=vertical]:my-0",
lg: "my-6 data-[orientation=vertical]:mx-6 data-[orientation=vertical]:my-0",
},
/* Pure spacing: keeps the gap, drops the rules around the label. */
line: {
true: "before:h-px before:flex-1 before:bg-newt-border before:content-[''] after:h-px after:flex-1 after:bg-newt-border after:content-[''] data-[orientation=vertical]:before:h-auto data-[orientation=vertical]:before:w-px data-[orientation=vertical]:after:h-auto data-[orientation=vertical]:after:w-px",
false: "",
},
},
defaultVariants: {
spacing: "md",
line: true,
},
}
)
export type DividerVariants = VariantProps<typeof dividerVariants>Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Divider to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Divider to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Divider } from "@/components/ui/divider"
export function Example() {
return <Divider />
}<script setup lang="ts">
import { Divider } from "@/components/ui/divider"
</script>
<template>
<Divider />
</template>API reference
Divider
spacing?"small" | "large" | "sm" | "md" | "lg"
Margin around the rule. `small` and `large` are the 4px and 8px steps of a Components V2 separator. `sm`, `md` and `lg` are 4px, 16px and 24px.
"small" | "large" | "sm" | "md" | "lg""md"line?boolean
Set it to `false` to keep the spacing and the label and remove the rules.
booleantrueorientation?"horizontal" | "vertical"
Direction of the rule. A vertical divider stretches to the height of its flex row.
"horizontal" | "vertical""horizontal"decorative?boolean
Set it to `true` when the rule is only visual. Assistive technology then ignores it.
booleanfalsechildren / default slot?React.ReactNode / Vue slot
Optional label in the centre of the rule.
React.ReactNode / Vue slotasChild / as-child?boolean
Puts the divider classes and role on the child element.
booleanfalseDivider renders a <div> and accepts its native attributes. React uses className, while Vue uses class. dividerVariants gives the same classes to an element of your own.
Accessibility
The divider has role="separator". A vertical divider also has aria-orientation="vertical". A screen reader announces the separator and can ignore its content. If the label carries meaning, such as a date, repeat it in an aria-label on the divider. Set decorative when the rule only adds space, and the divider leaves the accessibility tree.
Tokens
Divider reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-divider.
--newt-text-muted--newt-border