Utilities
Typography
Type roles as components. Heading picks a level for structure and a role for looks; reveal rises words in.
Examples and variants
Roles
headline, title, body, caption.
Quiet until you act
Title role
Body text uses the body role.
Captionfunction TypographyRoles() {
return (
<div className="flex w-full max-w-md flex-col gap-2">
<Heading level={2} role="headline" reveal>
Quiet until you act
</Heading>
<Heading level={3} role="title">
Title role
</Heading>
<Text>Body text uses the body role.</Text>
<Text role="caption" muted as="span">
Caption
</Text>
</div>
)
}Spec drawing
Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.
Install
With the CLI
The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/typography.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install cnCopy this file to the same paths in your project. Imports use the
@/alias for your project root.components/ui/typography.tsxtypography
components/ui/typography.tsximport * as React from "react" import { cn } from "cn" /* Typography: the type role tokens as components. Pick the heading level for the document outline and the role for the look; they're separate on purpose. `reveal` (marketing headings only) rises the words in one by one. */ const roles = { display: "text-[length:var(--type-display-size)] leading-(--type-display-leading) font-(--type-display-weight) tracking-(--type-display-tracking)", headline: "text-[length:var(--type-headline-size)] leading-(--type-headline-leading) font-(--type-headline-weight) tracking-(--type-headline-tracking)", title: "text-title", body: "text-body", label: "text-label", caption: "text-caption uppercase", mono: "font-mono text-mono", } as const type Role = keyof typeof roles function Heading({ level = 2, role = "headline", reveal = false, shimmer = false, className, children, ...props }: React.ComponentProps<"h2"> & { level?: 1 | 2 | 3 | 4 | 5 | 6 role?: Role reveal?: boolean /** A highlight sweeps across the letters once per hover (marketing headings). */ shimmer?: boolean }) { const Tag = `h${level}` as "h2" const content = reveal && typeof children === "string" ? children.split(" ").map((word, index) => ( <span key={index} className="heading-word inline-block" style={{ "--word": index } as React.CSSProperties}> {word} {" "} </span> )) : children return ( <Tag data-slot="heading" aria-label={reveal && typeof children === "string" ? children : undefined} className={cn(roles[role], shimmer && "heading-shimmer", className)} {...props}> {content} </Tag> ) } function Text({ role = "body", as: Tag = "p", muted = false, className, ...props }: React.ComponentProps<"p"> & { role?: Role; as?: "p" | "span" | "div"; muted?: boolean }) { return <Tag data-slot="text" className={cn(roles[role], muted && "text-muted-foreground", className)} {...props} /> } export { Heading, Text }
Imports
What the examples on this page import:
import { InfoIcon } from "lucide-react"
import { Alert, AlertTitle } from "@/components/ui/alert"
import { AspectRatio } from "@/components/ui/aspect-ratio"
import { Button } from "@/components/ui/button"
import { Collapsible, CollapsibleContent, CollapsibleLabel, CollapsibleTrigger } from "@/components/ui/collapsible"
import { DirectionProvider } from "@/components/ui/direction"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Heading, Text } from "@/components/ui/typography"Anatomy
- 1Heading / Text · --type-*-size, -leading, -weight, -tracking.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
Heading level | 1 to 6 | 2 | Document outline. |
role | "display" | "headline" | "title" | "body" | "label" | "caption" | "mono" | — | Look. |
reveal | boolean | — | Word-by-word rise (marketing only). |
shimmer | boolean | — | A highlight sweeps across once per hover. |
Tokens
Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.
This utility has no component tokens; it uses semantic tokens directly.
| Token | Points to | Light | Dark |
|---|
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Mount (reveal) | Words rise in with a stagger. | --duration-settle, --duration-stagger |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- Pick levels for structure, not size.
Code
import * as React from "react"
import { cn } from "cn"
/*
Typography: the type role tokens as components. Pick the heading level for
the document outline and the role for the look; they're separate on purpose.
`reveal` (marketing headings only) rises the words in one by one.
*/
const roles = {
display: "text-[length:var(--type-display-size)] leading-(--type-display-leading) font-(--type-display-weight) tracking-(--type-display-tracking)",
headline: "text-[length:var(--type-headline-size)] leading-(--type-headline-leading) font-(--type-headline-weight) tracking-(--type-headline-tracking)",
title: "text-title",
body: "text-body",
label: "text-label",
caption: "text-caption uppercase",
mono: "font-mono text-mono",
} as const
type Role = keyof typeof roles
function Heading({
level = 2,
role = "headline",
reveal = false,
shimmer = false,
className,
children,
...props
}: React.ComponentProps<"h2"> & {
level?: 1 | 2 | 3 | 4 | 5 | 6
role?: Role
reveal?: boolean
/** A highlight sweeps across the letters once per hover (marketing headings). */
shimmer?: boolean
}) {
const Tag = `h${level}` as "h2"
const content =
reveal && typeof children === "string"
? children.split(" ").map((word, index) => (
<span key={index} className="heading-word inline-block" style={{ "--word": index } as React.CSSProperties}>
{word}
{" "}
</span>
))
: children
return (
<Tag data-slot="heading" aria-label={reveal && typeof children === "string" ? children : undefined} className={cn(roles[role], shimmer && "heading-shimmer", className)} {...props}>
{content}
</Tag>
)
}
function Text({
role = "body",
as: Tag = "p",
muted = false,
className,
...props
}: React.ComponentProps<"p"> & { role?: Role; as?: "p" | "span" | "div"; muted?: boolean }) {
return <Tag data-slot="text" className={cn(roles[role], muted && "text-muted-foreground", className)} {...props} />
}
export { Heading, Text }