Typography tokens for consistent text across the design system.
Fragment UI uses Geist as the primary font family with system fallbacks. The typography system supports both sans-serif and monospace fonts.
--typography-font-sansGeist, ui-sans-serif, system-ui, sans-serif--typography-font-monoui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospaceThe typography system provides a font-size scale driven by tokens:
--typography-size-xs12px--typography-size-intro15px--typography-size-sm14px--typography-size-md16px--typography-size-lg18px--typography-size-xl20px--typography-size-2xl22pxFragment UI supports five font weights for different text hierarchies and emphasis:
--typography-weight-lightLight--typography-weight-regularRegular--typography-weight-mediumMedium--typography-weight-semiboldSemibold--typography-weight-boldBoldLarge display text styles for headings and hero sections. These styles use tighter line heights and negative letter spacing for impact.
text-display-2xltext-display-xltext-display-lgtext-display-mdtext-display-smtext-display-xsBody text styles for paragraphs and content. These styles use comfortable line heights for readability.
text-2xltext-xltext-lgtext-mdtext-introtext-smtext-xsIn Fragment UI docs, semantic HTML elements (headings, paragraphs, lists, inline code, strong/emphasis) are styled by DocumentContent using DS typography tokens. This avoids duplicating (and potentially drifting) hardcoded values in the documentation.
List styles for ordered and unordered lists:
Monospace font styles for code blocks and inline code:
Use inline code for short code snippets within paragraphs.
const fragment = "design system";
const tokens = { typography: "system" };
console.log(fragment, tokens);Here are practical examples of how to use typography tokens and styles in your components:
/* Font families */
font-family: var(--typography-font-sans);
font-family: var(--typography-font-mono);
/* Font sizes */
font-size: var(--typography-size-xs); /* 12px */
font-size: var(--typography-size-intro); /* 15px */
font-size: var(--typography-size-sm); /* 14px */
font-size: var(--typography-size-md); /* 16px */
font-size: var(--typography-size-lg); /* 18px */
font-size: var(--typography-size-xl); /* 20px */
font-size: var(--typography-size-2xl); /* 22px */
/* Using with density multipliers */
font-size: calc(var(--typography-size-md) * var(--density-typography-size-multiplier));Note: Tailwind utilities like text-xs are fixed rem-based sizes. If you want typography to be driven by design tokens (and respond to Theme Builder / density), prefer text-[length:var(--typography-size-*)] (or inline styles with var(--typography-size-*)).
/* Display styles */
<h1 className="text-display-2xl">Display Heading</h1>
<h2 className="text-display-xl">Large Display</h2>
/* Text styles */
<p className="text-[length:var(--typography-size-lg)]">Large text</p>
<p className="text-[length:var(--typography-size-md)]">Medium text</p>
<p className="text-[length:var(--typography-size-sm)]">Small text</p>
<p className="text-[length:var(--typography-size-xs)]">Extra small text</p>
/* Font weights */
<p className="font-light">Light (300)</p>
<p className="font-normal">Regular (400)</p>
<p className="font-medium">Medium (500)</p>
<p className="font-semibold">Semibold (600)</p>
<p className="font-bold">Bold (700)</p>
/* Font families */
<p className="font-sans">Sans-serif text</p>
<code className="font-mono">Monospace code</code>import { cn } from "@/lib/utils";
// Display heading
<h1
className={cn(
"text-display-lg",
"font-medium",
"text-[color:var(--foreground-primary)]"
)}
>
Hero Title
</h1>
// Body text
<p
style={{
fontFamily: "Geist, sans-serif",
fontSize: "var(--typography-size-md)",
fontWeight: 300,
lineHeight: "160%",
}}
>
Body text content
</p>
// Code block
<pre className="font-mono text-[length:var(--typography-size-sm)] bg-[color:var(--color-surface-2)] p-[var(--space-4)] rounded-[var(--radius-md)]">
<code>const code = "example";</code>
</pre>Typography scales automatically with density modes. See Density documentation for more details on how typography adapts to different density settings.