Text
Typography with 8 sizes, 9 intent colors, heading and overline presets, and weight, font and line-height props. It renders a paragraph by default; pick another element, like a heading, with render.
- @ui-sdk/react
- class-variance-authority
Sizes
Display — The interface that takes off
2XL — Main heading
XL — Subheading
LG — Body large, for highlighted paragraphs
MD — Body default, the standard size
SM — Small text, for notes and labels
XS — Caption · tracking wide · ideal for metadata
2XS — Fine print and compact labels
import { Text } from "@/components/ui/text"
export function TextSizesDemo() {
return (
<div className="space-y-2">
<Text size="display" leading="none">
Display — The interface that takes off
</Text>
<Text size="2xl">2XL — Main heading</Text>
<Text size="xl">XL — Subheading</Text>
<Text size="lg">LG — Body large, for highlighted paragraphs</Text>
<Text size="md">MD — Body default, the standard size</Text>
<Text size="sm" color="muted">
SM — Small text, for notes and labels
</Text>
<Text size="xs" color="muted">
XS — Caption · tracking wide · ideal for metadata
</Text>
<Text size="2xs" color="muted">
2XS — Fine print and compact labels
</Text>
</div>
)
}Colors
Default — foreground
primary — primary text
secondary — secondary text
muted — muted text
primary-muted — primary at 60%
secondary-muted — secondary at 60%
info — informational
warning — warning
success — confirmation
error — attention
import { Text } from "@/components/ui/text"
export function TextColorsDemo() {
return (
<div className="space-y-1.5">
<Text size="sm">Default — foreground</Text>
<Text size="sm" color="primary">primary — primary text</Text>
<Text size="sm" color="secondary">secondary — secondary text</Text>
<Text size="sm" color="muted">muted — muted text</Text>
<Text size="sm" color="primary-muted">primary-muted — primary at 60%</Text>
<Text size="sm" color="secondary-muted">secondary-muted — secondary at 60%</Text>
<Text size="sm" color="info">info — informational</Text>
<Text size="sm" color="warning">warning — warning</Text>
<Text size="sm" color="success">success — confirmation</Text>
<Text size="sm" color="error">error — attention</Text>
</div>
)
}Variants and type props
variant sets a role preset; weight, font, leading and color adjust it. Reach for className only for layout, like margins.
Overline · section label
Heading — semibold, tight tracking
Body with relaxed leading, for longer paragraphs that need room to breathe between lines.
Medium weight · card titles and labels
font="mono" · metadata and code-like values
Inline text keeps its parent's size: size="inherit"
import { Text } from "@/components/ui/text"
// Role presets and type props, so most text needs no className.
export function TextVariantsDemo() {
return (
<div className="space-y-3">
<Text variant="overline" size="xs">Overline · section label</Text>
<Text variant="heading" size="2xl">Heading — semibold, tight tracking</Text>
<Text color="muted" leading="relaxed">
Body with relaxed leading, for longer paragraphs that need room to breathe between lines.
</Text>
<Text size="sm" weight="medium">Medium weight · card titles and labels</Text>
<Text size="sm" font="mono" color="muted">font="mono" · metadata and code-like values</Text>
<Text size="sm">
Inline text keeps its parent's size:{" "}
<Text render={<span />} size="inherit" color="primary" weight="semibold">
size="inherit"
</Text>
</Text>
</div>
)
}HTML element
render sets the element; size and color stay independent of it, so the document outline and the visual scale don't have to match.
p styled as 2xl — a heading-sized paragraph
span — inline textimport { Text } from "@/components/ui/text"
// `render` picks the element; size and color stay independent of it.
export function TextElementDemo() {
return (
<div className="space-y-1.5">
<Text render={<p />} size="2xl">p styled as 2xl — a heading-sized paragraph</Text>
<Text render={<span />} size="sm" color="muted" className="block">
span — inline text
</Text>
<Text render={<label htmlFor="demo-email" />} size="sm" className="block">
label — form label
</Text>
<input id="demo-email" type="email" placeholder="you@example.com" className="h-8 rounded-md border border-input bg-background px-2 text-sm" />
</div>
)
}Customization
Bold with tight tracking
Muted text + italic
Decorative underline
Inline badge
import { Text } from "@/components/ui/text"
// className is merged after the variants, so it can extend or override any base style.
export function TextCustomizationDemo() {
return (
<div className="space-y-2">
<Text size="lg" className="font-black tracking-tight">
Bold with tight tracking
</Text>
<Text size="sm" color="muted" className="italic">
Muted text + italic
</Text>
<Text className="underline decoration-primary decoration-wavy">Decorative underline</Text>
<Text size="sm" className="w-fit rounded bg-primary/10 px-2 py-0.5 text-primary">
Inline badge
</Text>
</div>
)
}Installation
npx shadcn@latest add https://lanzate-ui.vercel.app/r/text.jsonUsage
import { Text } from "@/components/ui/text"
// Default paragraph (size="md")
<Text>Standard body text.</Text>
// h1 with the display size
<Text render={<h1 />} size="display">
The interface that takes off
</Text>
// Caption with an intent color
<Text render={<span />} size="xs" color="muted">
Last updated: 2 min ago
</Text>
// Section label
<Text variant="overline" size="xs">Installation</Text>
// Section title
<Text render={<h2 />} variant="heading" size="display">
One command and you're in orbit
</Text>
// Error message
<Text size="sm" color="error">
This field is required.
</Text>API
| Prop | Type | Default | Description |
|---|---|---|---|
render | ReactElement | (props) => ReactElement | <p /> | Element to render instead of <p>, like render={<h1 />}. Same render prop as ui-sdk parts. |
size | "2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "display" | "inherit" | "md" | Size from the type-scale tokens, with matching line height and tracking. "inherit" keeps the parent's size, for inline text. |
variant | "body" | "heading" | "overline" | "body" | Role preset. heading: the heading font (--font-heading), semibold, tight tracking. overline: a small mono, uppercase, muted label. |
weight | "normal" | "medium" | "semibold" | Font weight. Overrides the variant's. | |
font | "sans" | "mono" | Font family. | |
leading | "none" | "tight" | "snug" | "normal" | "relaxed" | Line height. Overrides the one the size sets. | |
color | "primary" | "secondary" | "muted" | "primary-muted" | "secondary-muted" | "info" | "warning" | "success" | "error" | "inherit" | Intent color. Overrides the variant's. Without it, the text uses the foreground color. `inherit` takes the parent's color, for text inside a control that colors its own states. | |
className | string | Classes merged after the variants, so they can extend or override any base style. |