Skip to content

Typography

Terminal-styled typography wrapper for consistent text styling. Provides variants for body text, prose content, and compact displays, plus semantic h1-h6 headings with sensible default sizing.

Preview

Installation

$pnpm exec dgadd add ui/typography
[Installs to]src/components/ui/typography[Item]ui/typography

dgadd is not public on npm yet. Until the first release, pack @diffgazer/add from the repository and install that tarball into this app, which is what puts dgadd on pnpm exec.

UI components require Tailwind CSS v4. Local copy mode imports src/styles/styles.css; package mode uses @diffgazer/ui CSS once packages are available.

Usage

tsx
import { Typography } from "@/components/ui/typography";function DemoLabel({ children }: { children: string }) {  return (    <span className="text-xs text-muted-foreground uppercase tracking-wider mb-2 block">      {children}    </span>  );}export default function TypographyDefault() {  return (    <div className="space-y-6">      <div>        <DemoLabel>default (sm)</DemoLabel>        <Typography>          Standard body text for UI labels, descriptions, and general content. Optimized for          readability at small sizes with relaxed line spacing.        </Typography>      </div>      <div>        <DemoLabel>prose</DemoLabel>        <Typography as="p" variant="prose">          Prose variant uses looser line spacing for comfortable reading of longer-form content like          documentation and articles. Multiple paragraphs flow naturally with consistent vertical          rhythm.        </Typography>      </div>      <div>        <DemoLabel>compact (xs)</DemoLabel>        <Typography as="p" variant="compact" size="xs">          Compact variant uses smaller text with tighter spacing, suitable for secondary          information, captions, and dense data displays.        </Typography>      </div>      <div>        <DemoLabel>size=base</DemoLabel>        <Typography size="base">          Base size text for when you need slightly larger body copy.        </Typography>      </div>      <div>        <DemoLabel>truncate</DemoLabel>        {/* The border makes the width constraint visible: the text is cut at the box edge. */}        <div className="max-w-xs border border-border p-2">          <Typography truncate>            This text will be truncated with an ellipsis when it overflows its container boundary.          </Typography>        </div>      </div>      <div>        <DemoLabel>lineClamp=2</DemoLabel>        <div className="max-w-sm border border-border p-2">          <Typography lineClamp={2}>            This text is clamped to two lines. Any content beyond the second line will be hidden            with an ellipsis. Useful for card descriptions, preview text, and anywhere you need            controlled text overflow.          </Typography>        </div>      </div>    </div>  );}

Semantic headings

Pass as="h1" through as="h6" to render semantic heading elements. Each level ships with a sensible default size; pass an explicit size prop to override.

asDefault size
h13xl
h22xl
h3xl
h4lg
h5base
h6sm
Preview

SectionHeader remains the right primitive for the small, uppercase, tracked section labels common throughout the product surface; reach for Typography when you need general semantic headings outside that pattern.

Weights and colors

weight and color are independent axes on every size. color="accent" reads the theme accent token, so it stays a deliberate highlight in both palettes.

Preview

API Reference

Typography

NameTypeDefaultDescription
as"div" | "p" | "span" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6""div"Rendered HTML element. Use h1-h6 for semantic headings.
variant"default" | "prose" | "compact""default"Line-height token. Default for UI text, prose for long-form, compact for dense info.
size"xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl""sm" (for non-headings); h1=3xl, h2=2xl, h3=xl, h4=lg, h5=base, h6=smFont-size token. Explicit value overrides the heading default.
weight"normal" | "medium" | "semibold" | "bold""normal" (for non-headings); h1-h6 auto-default to "bold"Font-weight token. Explicit value overrides the heading default.
color"default" | "muted" | "accent""default"Text color token. default uses the foreground color, muted uses muted-foreground, accent uses the theme accent.
lineClamp1 | 2 | 3 | 4 | 5 | 6Truncates after the given number of lines with an ellipsis.
truncatebooleanfalseSingle-line truncation with ellipsis.
childrenReactNodeText content.

Accessibility

Notes

Variants

Use 'default' for general UI text, 'prose' for longer-form content with wider line-height, and 'compact' for dense secondary information.

Semantic Elements

Use the 'as' prop to render the appropriate HTML element: 'p' for paragraphs, 'span' for inline text, 'div' for block content, and 'h1'-'h6' for semantic headings. Defaults to 'div'.

Heading Defaults

Each heading level has a default size (h1 = 3xl, h2 = 2xl, h3 = xl, h4 = lg, h5 = base, h6 = sm) and auto-defaults to bold weight. Pass explicit 'size' or 'weight' props to override.

Heading Semantics

Only 'as' decides the document outline: 'size' is purely visual and never changes the rendered element. Pick the heading level that follows the surrounding outline, then set 'size' to match the visual hierarchy — never pick 'as' to obtain a size.

Source

Install via CLI: pnpm exec dgadd add ui/typography.

Highlighted source loads after this disclosure opens. Browse the source repository.