Typography — Fluid Scales & Modern Features
Typography
Font stacks — system fonts are great
/* System UI — looks native everywhere, instant render, no network */
:root {
--font-sans: system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
--font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo,
Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
--font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
}
Web fonts are a luxury, not a default. If you load them:
- Preload the critical 1-2 weights
- Use
font-display: swap(oroptionalfor less-critical) - Subset to the chars you actually use
Fluid type scale
:root {
/* Modular scale based on 1.25 ratio */
--fs-100: clamp(0.75rem, 0.7rem + 0.25vw, 0.85rem);
--fs-200: clamp(0.85rem, 0.8rem + 0.3vw, 0.95rem);
--fs-300: clamp(0.95rem, 0.9rem + 0.4vw, 1.05rem); /* body */
--fs-400: clamp(1.1rem, 1rem + 0.5vw, 1.25rem);
--fs-500: clamp(1.3rem, 1.15rem + 0.75vw, 1.5rem);
--fs-600: clamp(1.6rem, 1.3rem + 1.5vw, 2.1rem);
--fs-700: clamp(2rem, 1.5rem + 2.5vw, 3rem);
--fs-800: clamp(2.5rem, 1.8rem + 3.5vw, 4rem);
}
Output in rem — never px for font sizes. Users with browser font-zoom or system font-size settings won’t be able to scale your text.
Vertical rhythm
:root {
--line-base: 1.5; /* body line-height */
--space-3xs: 0.25rem;
--space-2xs: 0.5rem;
--space-xs: 0.75rem;
--space-s: 1rem;
--space-m: 1.5rem;
--space-l: 2rem;
--space-xl: 3rem;
--space-2xl: 4rem;
--space-3xl: 6rem;
}
body {
font-size: var(--fs-300);
line-height: var(--line-base);
}
h1, h2, h3 { line-height: 1.2; margin-block: var(--space-m); }
Text wrap — modern options
.balance-me {
text-wrap: balance; /* equal-width lines for headings ≤6 lines */
}
.body-text {
text-wrap: pretty; /* better orphans/widows for body text */
/* Note: pretty has minor perf cost — use for body content, not all text */
}
/* Prevent hyphenation artifacts */
.no-hyphens { hyphens: manual; }
OpenType features — for monospace & display fonts
.mono {
font-feature-settings: "tnum" 1, "calt" 1; /* tabular numbers, contextual alternates */
font-variant-numeric: tabular-nums;
}
.heading {
font-feature-settings: "liga" 1, "kern" 1; /* ligatures, kerning */
}
Common features:
tnum— tabular numbers (aligns decimals in tables)lnum— lining figures (default in most fonts)onum— old-style figures (lowercase-style numerals)frac—1/2instead of1⁄2kern— kerningliga— ligatures
The ::first-letter and ::first-line pseudo-elements
.intro::first-letter {
float: left;
font-size: 3em;
line-height: 0.85;
margin-right: 0.1em;
font-weight: bold;
}
Variable fonts — one file, infinite styles
@font-face {
font-family: 'Inter';
src: url('/fonts/Inter-Variable.woff2') format('woff2-variations');
font-weight: 100 900; /* axis range */
font-style: normal;
font-display: swap;
}
.inter-thin { font-weight: 250; }
.inter-bold { font-weight: 750; }
/* Or use optical sizing */
.text-large {
font-variation-settings: "opsz" 144; /* optical size axis */
}
Variable axes:
wght— weight (100-900)slnt— slantital— italicopsz— optical size (small text vs display)GRAD— grade (Apple’s font grade)
Truncation patterns
/* Single-line ellipsis */
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Multi-line clamp */
.line-clamp-3 {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
/* Modern (Chrome 120+, FF 125+) */
.line-clamp-3 {
line-clamp: 3;
}
Kerning & spacing
.heading {
letter-spacing: -0.02em; /* tighter for large display text */
}
.eyebrow {
letter-spacing: 0.08em; /* wider for all-caps labels */
text-transform: uppercase;
font-size: 0.75em;
}
Pitfalls
- Pixel font-sizes break user font-zoom. Use
rem. <br>for spacing — usemargin-blockinstead.text-align: justify— ruins readability on narrow screens.- All-caps without letter-spacing — looks cramped.
- Long line lengths — keep ≤75 characters (
max-width: 65ch).
Comments (0)
No comments yet.
Log in to post a comment.