Heading
Display, section and card headings with optional fit-to-width and reveal.
level picks the size and as picks the element, so the look and the outline are chosen apart: level="h1" as="h3" is a display heading that is a third-level heading. size overrides the size of the level.
Levels
level="h1"
Ship the release
level="h2"
Ship the release
level="h3"
Ship the release
level="h4"
Ship the release
import { Heading } from "@/components/ui/heading"
const levels = ["h1", "h2", "h3", "h4"] as const
export default function HeadingLevels() {
return (
<div className="flex w-full flex-col gap-6">
{levels.map((level) => (
<div key={level} className="flex flex-col gap-1">
<span className="font-mono text-xs text-muted-foreground">level="{level}"</span>
<Heading level={level} as="h3" animated={false}>
Ship the release
</Heading>
</div>
))}
</div>
)
}
Sizes
size="display"
Invoices this month
size="section"
Invoices this month
size="card"
Invoices this month
size="inline"
Invoices this month
import { Heading } from "@/components/ui/heading"
const sizes = ["display", "section", "card", "inline"] as const
export default function HeadingSizes() {
return (
<div className="flex w-full flex-col gap-6">
{sizes.map((size) => (
<div key={size} className="flex flex-col gap-1">
<span className="font-mono text-xs text-muted-foreground">size="{size}"</span>
<Heading as="h3" size={size} animated={false}>
Invoices this month
</Heading>
</div>
))}
</div>
)
}
Fit to width
Release 4.2
Fourteen changes, shipped on Tuesday
import { Heading } from "@/components/ui/heading"
export default function HeadingFitToWidth() {
return (
<div className="flex w-full flex-col gap-2">
<Heading as="h3" size="display-xl">
Release 4.2
</Heading>
<Heading as="h3" size="card" fit textColor="muted">
Fourteen changes, shipped on Tuesday
</Heading>
</div>
)
}
Reveal
Every task closed, two days ahead of the release
"use client"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { Heading } from "@/components/ui/heading"
export default function HeadingReveal() {
const [run, setRun] = React.useState(0)
return (
<div className="flex w-full flex-col gap-4">
<Heading key={run} as="h3" size="card">
Every task closed, two days ahead of the release
</Heading>
<Button variant="outline" className="self-start" onClick={() => setRun(run + 1)}>
Play again
</Button>
</div>
)
}
Weight and colour
Medium, the default
Normal weight
Muted colour
import { Heading } from "@/components/ui/heading"
export default function HeadingWeightAndColour() {
return (
<div className="flex w-full flex-col gap-3">
<Heading as="h3" size="card" animated={false}>
Medium, the default
</Heading>
<Heading as="h3" size="card" weight="normal" animated={false}>
Normal weight
</Heading>
<Heading as="h3" size="card" textColor="muted" animated={false}>
Muted colour
</Heading>
</div>
)
}
Installation
npx shadcn@latest add @khaeli/headingbunx --bun shadcn@latest add @khaeli/headingInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- class-variance-authority ^0.7.1
Accessible name
- A plain-text heading is revealed line by line. The full text stays in the heading for assistive technology and the animated lines are hidden from it. With reduced motion the text is shown at once.
- Pass
animated={false}for a heading that should not move.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/heading.json