Hairline
Hairline rule component: a 1px line in the border color whose ends fade out, for the line between two sections of a page, with a plain option for a rule inside a frame. Built on the stock Separator.
import type { ComponentProps } from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "cn"
import { Separator } from "@/components/ui/separator"
/**
* ends paints the line as a gradient so it dissolves over its first and last
* tenth instead of stopping; Separator's own bg-border has to go, or it shows
* through the transparent ends.
*/
const hairlineVariants = cva("", {
variants: {
/**
* How the line ends. `ends` (the default) fades it out over the first
* and last tenth, so a full-width line never reads as a bar across the
* page. `none` is a plain line, for a rule inside a frame.
*/
fade: {
ends: "bg-transparent data-horizontal:bg-[linear-gradient(to_right,transparent,var(--border)_10%,var(--border)_90%,transparent)] data-vertical:bg-[linear-gradient(to_bottom,transparent,var(--border)_10%,var(--border)_90%,transparent)]",
none: "",
},
},
defaultVariants: { fade: "ends" },
})
/**
* A 1px rule in the border color whose ends dissolve: the line between two
* sections of a page. It is the stock `Separator` underneath, so it takes
* `orientation` and `className` the same way.
*
* `fade="ends"` (the default) paints the line as a gradient, transparent at
* each end and the border color from 10% to 90%. `fade="none"` is a plain
* line. `decorative` (the default) hides it from assistive technology, since
* two sections are already separate landmarks; pass `decorative={false}` for
* a separator that means something, such as one between groups in a list.
* It carries no margin: leave the space around it to the layout, as with
* any rule.
*/
function Hairline({
className,
fade = "ends",
decorative = true,
...props
}: ComponentProps<typeof Separator> &
VariantProps<typeof hairlineVariants> & {
/** Hide the line from assistive technology (the default). `false` keeps the separator role. */
decorative?: boolean
}) {
return (
<Separator
data-slot="hairline"
data-fade={fade}
aria-hidden={decorative || undefined}
className={cn(hairlineVariants({ fade }), className)}
{...props}
/>
)
}
export { Hairline, hairlineVariants }
import { Hairline } from "@/components/hairline/hairline"
// The copy: change text here, not in the markup.
const COPY = {
first: "Blocks that read like a studio made them.",
second: "Scenes and orbs for the quiet parts of a page.",
rowOne: "Studio",
rowTwo: "Scenes",
} as const
/** Hairline with faded ends between two lines of copy, then a plain one inside a frame. */
export default function HairlineDemo() {
return (
<div className="grid w-full max-w-2xl gap-10">
<div>
<p className="py-8 text-lg/7 text-foreground">{COPY.first}</p>
<Hairline />
<p className="py-8 text-lg/7 text-foreground">{COPY.second}</p>
</div>
<div className="mx-auto w-full max-w-xs rounded-sm border text-sm/6 text-foreground">
<p className="px-4 py-3">{COPY.rowOne}</p>
<Hairline fade="none" />
<p className="px-4 py-3">{COPY.rowTwo}</p>
</div>
</div>
)
}
Installation
pnpm dlx shadcn@latest add @01orbital/hairlinenpx shadcn@latest add @01orbital/hairlineyarn dlx shadcn@latest add @01orbital/hairlinebunx --bun shadcn@latest add @01orbital/hairlineUsage
import { Hairline } from "@/components/hairline/hairline"
// The copy: change text here, not in the markup.
const COPY = {
first: "Blocks that read like a studio made them.",
second: "Scenes and orbs for the quiet parts of a page.",
rowOne: "Studio",
rowTwo: "Scenes",
} as const
/** Hairline with faded ends between two lines of copy, then a plain one inside a frame. */
export default function HairlineDemo() {
return (
<div className="grid w-full max-w-2xl gap-10">
<div>
<p className="py-8 text-lg/7 text-foreground">{COPY.first}</p>
<Hairline />
<p className="py-8 text-lg/7 text-foreground">{COPY.second}</p>
</div>
<div className="mx-auto w-full max-w-xs rounded-sm border text-sm/6 text-foreground">
<p className="px-4 py-3">{COPY.rowOne}</p>
<Hairline fade="none" />
<p className="px-4 py-3">{COPY.rowTwo}</p>
</div>
</div>
)
}This example installs with everything it uses:
pnpm dlx shadcn@latest add @01orbital/hairline-demonpx shadcn@latest add @01orbital/hairline-demoyarn dlx shadcn@latest add @01orbital/hairline-demobunx --bun shadcn@latest add @01orbital/hairline-demoAPI reference
A 1px rule in the border color whose ends dissolve: the line between two sections of a page. It is the stock Separator underneath, so it takes orientation and className the same way.
fade="ends" (the default) paints the line as a gradient, transparent at each end and the border color from 10% to 90%. fade="none" is a plain line. decorative (the default) hides it from assistive technology, since two sections are already separate landmarks; pass decorative={false} for a separator that means something, such as one between groups in a list. It carries no margin: leave the space around it to the layout, as with any rule.
Prop
Type
It also accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.
Dependencies
npm: class-variance-authority, cn. The CLI installs them for you.
Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Used in blocks
8 blocks are built with Hairline:
Base Plan With Add-ons
Editorial Colophon Footer
Footer With Compliance Badges
Footer With Office Addresses
Install Hero with Agent Logos
Quote with brand row
Seat Slider Pricing
Wayfinding Navbar
Last updated on