Typography System
Font families, fluid sizes, type-style roles, leading trim, reading-comfort tokens, variable-font axes and scenario presets.
FlexPixels’ typography system is built from a small set of primitives
(font sizes, line heights, weights, letter-spacings, family slots,
variable-font axes) composed into semantic roles (body, title,
headline, display, caption, etc.). Roles carry intent metadata so AI
agents can pick the right token instead of guessing.
The whole thing is generated by the @flexpixels/cortex engine from
your theme-config.json. Sizes are precomputed rem (the fluid roles use
clamp()), and the same tokens are available as a DTCG export.
Quick start
/* Default UI text */
p {
font-family: var(--fp-text-body-font-family);
font-size: var(--fp-text-body-font-size);
line-height: var(--fp-text-body-line-height);
font-weight: var(--fp-text-body-font-weight);
letter-spacing: var(--fp-text-body-letter-spacing);
color: var(--fp-text-default);
}<!-- Long-form content: wrap it in fp-prose -->
<fp-prose measure>…</fp-prose>Primitives
Font families (--fp-font-family-*)
Three named slots — pick the right one per role.
--fp-font-family-display— titles, headlines, hero copy--fp-font-family-body— paragraphs, UI text (default)--fp-font-family-mono— code, data, ASCII art
Each role declares which slot it uses via fontFamily: "display" | "body" | "mono" in its typeStyles entry. Roles default to body.
Font sizes (--fp-font-size-*)
Step-based scale, 1-indexed, smallest first. All entries must be even integers when strictGrid is true (the default); set strictGrid: false for editorial scales that include 13, 15, etc. The default stylesheet keeps only the steps that other tokens or components use (a fluid role writes its own clamp() instead); the full stylesheet (theme-full.css, or output.tokens: "full") has every step. The same goes for the line heights below.
| Step | Size | Line height | Ratio | CSS variable |
|---|---|---|---|---|
| 1 | 12px (0.75rem) | 18px (1.125rem) | 150% | var(--fp-font-size-1) |
| 2 | 14px (0.875rem) | 22px (1.375rem) | 157% | var(--fp-font-size-2) |
| 3 | 16px (1rem) | 24px (1.5rem) | 150% | var(--fp-font-size-3) |
| 4 | 18px (1.125rem) | 28px (1.75rem) | 156% | var(--fp-font-size-4) |
| 5 | 20px (1.25rem) | 30px (1.875rem) | 150% | var(--fp-font-size-5) |
| 6 | 24px (1.5rem) | 36px (2.25rem) | 150% | var(--fp-font-size-6) |
| 7 | 32px (2rem) | 48px (3rem) | 150% | var(--fp-font-size-7) |
| 8 | 40px (2.5rem) | 60px (3.75rem) | 150% | var(--fp-font-size-8) |
| 9 | 48px (3rem) | 72px (4.5rem) | 150% | var(--fp-font-size-9) |
| 10 | 56px (3.5rem) | 84px (5.25rem) | 150% | var(--fp-font-size-10) |
| 11 | 64px (4rem) | 96px (6rem) | 150% | var(--fp-font-size-11) |
Line heights (--fp-line-height-*)
Auto-computed from font sizes via the configured lineHeightFormula:
| Formula key | Multiplier | Label | Best for |
|---|---|---|---|
ratio-1.5 | 1.5× | 1.5× ratio snapped to 2px grid | UI (default). Predictable rhythm for forms, cards, dashboards. |
golden | 1.618× | Golden ratio (1.618×) snapped to 2px grid | Editorial / long-form reading. |
compact | 1.3× | Compact 1.3× ratio snapped to 2px grid | Data-dense dashboards and tables. |
Named aliases point at fixed steps, whatever the formula:
--fp-line-height-flat—1(tight display headings, single line)--fp-line-height-tight— step 1 alias (captions)--fp-line-height-snug— step 2 alias (form labels)--fp-line-height-normal— step 3 alias (body)--fp-line-height-relaxed— step 4 alias (larger body / lead paragraphs)
Font weights (--fp-font-weight-*)
--fp-font-weight-regular: 400;
--fp-font-weight-medium: 500;
--fp-font-weight-semibold: 600;
--fp-font-weight-bold: 700;Letter-spacing (--fp-letter-spacing-*)
Named em values. Type-style letterSpacing can reference these by key ("wide") or pass a literal em number (-0.015). Only normal is in the default stylesheet, because every default role uses it; tighter, tight, snug and wide are in the full stylesheet only, unless a role in your theme points at them.
--fp-letter-spacing-tighter: -0.03em;
--fp-letter-spacing-tight: -0.02em;
--fp-letter-spacing-snug: -0.01em;
--fp-letter-spacing-normal: 0em;
--fp-letter-spacing-wide: 0.04em;Every default role tracks at normal (0): the font already tracks itself
per size. The other steps are there for a theme that wants tracking — point a
role’s letterSpacing at one of them in typeStyles.
Numeric figures (--fp-font-numeric-*)
Ready-to-use font-variant-numeric values for figures that must line up column-to-column:
--fp-font-numeric-tabular: tabular-nums;
--fp-font-numeric-tabular-slashed: tabular-nums slashed-zero; /* full stylesheet only */Consume them directly on any element with aligned figures:
.cell {
font-variant-numeric: var(--fp-font-numeric-tabular);
}Data-grid cells, the calendar day grid and progress labels already use them. The data grid and calendar also expose an override hook (--fp-data-grid-font-variant-numeric, --fp-calendar-font-variant-numeric).
Variable-font axes (optional — --fp-font-axis-*)
Configure typography.variableAxes to expose per-axis min/max/default. Each axis is a [min, max, default] tuple. Type styles can opt into weightAxis: number to target non-standard weights on variable fonts (e.g. 540 on InterVariable).
{
"typography": {
"variableAxes": { "wght": [100, 900, 400] }
}
}/* Emitted only when typography.variableAxes is set */
--fp-font-axis-wght-min: 100;
--fp-font-axis-wght-max: 900;
--fp-font-axis-wght-default: 400;Semantic type-style roles
Each role bundles font-size, line-height, font-weight, letter-spacing, font-family, plus optional lineHeightRatio (unitless, size-scaling leading — see below), text-transform, font-style, text-decoration, font-variant-numeric (aligned figures — set fontVariantNumeric: "tabular-nums"), opsz (variable-font optical), and leading trim. Consume via var(--fp-text-{role}-{property}).
Alongside the reading and heading roles, four inline/specialist roles round
out the vocabulary: code (inline code / <kbd>, mono family),
link (inline hyperlink, medium weight + underline), quote
(pull-quotes, blockquotes, testimonial body — upright, not italic), and
data (large numeric / metric display with tabular-nums aligned
figures).
| Role | Family | Size step | Weight | Intent |
|---|---|---|---|---|
caption | body | 1 | regular | Smallest readable text — secondary metadata that supports primary content. |
label | body | 2 | medium | Form-field and UI labels — short, scannable, slightly emphasized. |
body | body | 3 | regular | Primary reading text for long-form content and the default UI body copy. |
body-lg | body | 4 | regular | Slightly larger reading text — used for emphasis without crossing into title. |
title | display | 5 | semibold | Section title — the dominant heading inside a card, modal, or content block. |
headline | display | 6 | semibold | Page-level headline — typically the h1 inside an app screen or content view. |
display | display | 8 | bold | Largest display text — used sparingly for marketing impact. |
button | body | 2 | semibold | Text rendered inside interactive buttons — short, decisive, slightly emphasized. |
input | body | 3 | regular | Text typed into form inputs — matches body for visual continuity. |
helper | body | 1 | regular | Microcopy under form fields — explanations, validation hints, character counts. |
code | mono | 2 | regular | Inline code, keyboard keys, and fixed-width tokens embedded in prose. |
link | body | 3 | medium | Inline hyperlink text — slightly emphasized and underlined for affordance. |
quote | body | 4 | regular | Pull-quotes, blockquotes, and testimonial body — larger reading text that stays upright. |
data | body | 6 | semibold | Large numeric / metric display — KPIs, stat values, big figures with aligned digits. |
Read flexpixels://typography/roles/{role} from the Cortex MCP server for full
whenToUse / whenNotToUse / examples per role.
Two tiers: product roles vs layout roles
The roles above split into two deliberate tiers — reach for the one that matches the surface you’re building:
- Product roles (engine built-ins):
caption,label,body,body-lg,title,headline,display,button,input,helper,code,link,quote,data. The component library reads these roles. Use them for application UI. - Layout / marketing roles (not built in — defined in the
typeStylesof the repository’s and this site’stheme-config.json):eyebrow,section-subtitle,section-title,hero-title. They are the larger, more expressive sizes that layout components such asfp-heroandfp-sectionread for marketing pages. They use the same font-size scale as the product roles, reaching further up it:section-titleat step 8 andhero-titleat step 11 of a longer scale.
Both tiers emit the same --fp-text-{role}-* token shape, so you reference
them the same way. A theme without those typeStyles entries has no marketing
roles. Keep product UI on the product roles and
reserve the marketing roles for landing-page layout components.
Fluid sizing (Utopia-style clamp)
typography.fluid turns the font size of the larger roles into a clamp() that grows between two viewport widths. By default a role is fluid when its fontSizeStep is in the upper half of the scale:
{
"typography": {
"fluid": { "minViewport": 320, "maxViewport": 1280 },
// or: "fluid": false to disable globally
// or: "fluid": { ..., "roles": ["display", "headline"] } to restrict
},
}- With the default scale,
titlegetsclamp(1.25rem, 1.167rem + 0.417vw, 1.5rem): 20px at 320px wide, 24px at 1280px. It is also snapped withround()to the coarsest pixel grid both ends sit on: 0.25rem here, 0.125rem or 0.0625rem when an end is not a multiple of 4px, so the sizes the scale names are always reached. - Lower-half roles (e.g.
body,label) stay fixed — predictable for forms and dense UI. - The
--fp-font-size-*primitives never become fluid. - Per-role override:
typeStyles[role].fluid = false | true | { min, max }(min and max in px, min at most max). AtypeStylesentry replaces the role whole, so it also givesfontSizeStep,lineHeightStepandfontWeight.
Unitless heading leading (lineHeightRatio)
A constant ~1.5 line-height ratio over-leads large headings, and the fixed-rem --fp-line-height-{step} alias decouples leading from the fluid font size — so a heading that grows with the viewport keeps stale, oversized leading. To fix this, a role in typography.typeStyles can set an optional unitless lineHeightRatio (e.g. 1.1):
{
"typography": {
"typeStyles": {
"section-title": {
"fontSizeStep": 8,
"lineHeightStep": 8,
"fontWeight": "semibold",
"lineHeightRatio": 1.1,
},
"hero-title": {
"fontSizeStep": 8,
"lineHeightStep": 8,
"fontWeight": "bold",
"lineHeightRatio": 1.05,
},
},
},
}When set, the role emits a unitless line-height that scales with the font size, following fluid clamps, instead of the fixed-rem alias. Built-in title (1.25), headline (1.15), display (1.05) and data (1.15) already use it; the repository’s theme-config.json also sets section-title (1.1) and hero-title (1.05).
Body and reading roles deliberately omit lineHeightRatio so their leading stays snapped to the 2px vertical grid for predictable rhythm in long-form text.
Leading trim — font-metrics-aware
Every role gets two negative-em trim tokens, computed from the font metrics of its family slot. By default the engine uses Inter’s metrics for display and body and Geist Mono’s for mono:
.heading {
font-size: var(--fp-text-headline-font-size);
line-height: var(--fp-text-headline-line-height);
margin-top: var(--fp-text-headline-trim-top); /* e.g. -0.3475em */
margin-bottom: var(--fp-text-headline-trim-bottom); /* e.g. -0.075em */
}The effect is like CSS text-box-trim: text snaps to the cap-line at the top and the baseline at the bottom, removing the leading above and below. If you use other fonts, give their metrics in typography.metrics.{display|body|mono} so the trim matches them.
Reading-comfort tokens & fp-prose
--fp-text-comfort-line-length: 65ch;
--fp-text-comfort-min-size: 1rem;
--fp-text-comfort-max-line-height-ratio: 1.6;The engine emits the tokens; the fp-prose element (from @flexpixels/ui, which is not published yet) reads two of them. fp-prose always applies the body type style; measure adds the line-length cap (--fp-text-comfort-line-length) and the size floor (--fp-text-comfort-min-size). Nothing in @flexpixels/ui reads --fp-text-comfort-max-line-height-ratio; it is advisory. The engine no longer generates a .fp-prose class.
<fp-prose measure>
<h1>Reading-comfort defaults applied</h1>
<p>Wraps at 65ch, never smaller than 1rem, body line-height, body letter-spacing.</p>
</fp-prose>Scenario presets
Set typography.scenario to apply a curated bundle in one line. Your explicit fields still win — scenario only fills in what you didn’t set.
| Scenario | Scale (px) | Line-height formula | Fluid range | Best for |
|---|---|---|---|---|
marketing | 14, 16, 18, 20, 24, 32, 44, 56 | ratio-1.5 | 320–1280px | Body 18px, hero tops at 56px, 1.5× line-heights for impactful headlines. |
app | 12, 14, 16, 18, 20, 24, 32, 40 | ratio-1.5 | 320–1280px | Balanced UI scale — 16px body, 40px display max. |
editorial | 14, 16, 18, 20, 24, 30, 38, 48 | golden | 400–1440px | Body 18px, golden-ratio leading for long-form reading flow. |
dashboard | 12, 14, 16, 18, 20, 22, 26, 32 | compact | 320–1280px | Flat ramp (max 32px), compact (1.3×) leading for data density. |
{
"typography": {
"scenario": "editorial",
// Override: keep the editorial line-height formula but use a custom scale.
"scale": [16, 18, 20, 22, 26, 32, 40, 48],
},
}MCP tools (for AI agents)
The typography tools on the MCP server — call them when an agent is wiring typography or checking an existing config:
| Tool | Description |
|---|---|
compute_typography | Compute a full typography system. Pass intent or explicit scale. Returns scale, type-styles, CSS preview, warnings, rationale. |
validate_typography | Validate typography against readability + a11y guidance. Vet a candidate ThemeConfig, scan an HTML fragment's inline styles, or scan a stylesheet. |
pair_fonts | Suggest companion fonts for a primary family. Returns display/body/mono slots plus three alternative triplets. Curated offline list — no network. |
suggest_type_scale | Suggest 3 candidate font-size scales tuned to an intent (marketing/app/editorial/dashboard) with rationales and ready-to-paste typography config slices. |
Best practices
- Consume semantic roles, not primitives.
var(--fp-text-body-font-size)communicates intent;var(--fp-font-size-3)doesn’t. - Use a role’s tokens together. Each role ships its font size, line height, weight, letter-spacing and family; apply them as a set.
- Use leading trim for headlines. Apply
--fp-text-{role}-trim-top/-trim-bottomto optically center text within layout grids. - Wrap long-form text in
fp-prose measure. Cheap defaults (65ch, ≥1rem, body family/leading) with no per-page setup. - Pick a scenario before you tune.
typography.scenariosets the scale, the line-height formula and the fluid range in one line; override single fields rather than starting from scratch. - Ask the MCP server.
@flexpixels/cortex-mcpserves theflexpixels://typography/roles/{role}resource and thesuggest_type_scaleandvalidate_typographytools, so agents don’t have to guess.