For years, web developers relied on standard CSS resets to establish a baseline for digital typography. Traditional resets primarily focused on stripping away browser default margins, standardizing line heights, and forcing consistent base sizes across unpredictable user agents. However, layout engines and CSS specifications have evolved dramatically. Native CSS can now execute complex typesetting choices that previously required external JavaScript libraries, heavy build tools, or awkward visual hacks.
Properties like text-wrap: pretty can eliminate stranded orphan words at the end of paragraphs, container query units can dynamically scale component headings based on container width rather than the screen viewport, and the emerging text-box specification can trim the extra built-in half-leading from text boxes. Because browser support for some of these modern capabilities remains uneven, implementation requires thoughtful guardrails rather than uncritical application.
To address this shift, developer tools and custom stylesheets are evolving to group these rules into cohesive foundations. A standout example is tidy-typography.css, a default stylesheet designed to collect these modern capabilities into a reliable baseline. By addressing rendering behaviors, fallback logic, fluid container-based sizing, vertical rhythm, text wrapping, hyphenation, and OpenType controls, it demonstrates how modern CSS can systematically elevate web typesetting.
/* tidy-typography.css snippet preview */
html
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
font-synthesis: none;
-moz-text-size-adjust: none;
-webkit-text-size-adjust: none;
text-size-adjust: none;
Rendering and fallback sanity
Establishing predictable typography begins at the document root. Browsers frequently attempt to assist layouts by synthesizing font styles or automatically inflating text sizes on mobile devices, often creating unintended visual artifacts. Modern reset rules mitigate these behaviors by establishing strict rendering constraints early in the cascade.
html
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
font-synthesis: none;
-moz-text-size-adjust: none;
-webkit-text-size-adjust: none;
text-size-adjust: none;
body
font-size-adjust: from-font;
The font-synthesis: none declaration prevents layout engines from mathematically generating bold or italic variants when a chosen font family lacks native glyphs for those weights. Instead of displaying a distorted synthetic slant or artificially bolded letterform, the browser falls back gracefully to the actual available font styles.
Declarations such as -webkit-font-smoothing: antialiased and text-rendering: optimizeLegibility serve as rendering hints, particularly within WebKit-derived engines, instructing the graphics pipeline to prioritize kerning and legibility over raw text-rendering speed. Although platform-level rendering engines interpret these directives differently across operating systems, including them provides a cleaner baseline across desktop platforms.
On mobile viewports, default text inflation can alter intentionally sized elements when orientation changes. Setting text-size-adjust: none disables this automatic scaling, preserving explicit design hierarchies. To smooth the visual transition during web font loading, font-size-adjust: from-font uses the primary font’s inherent aspect ratio metrics to normalize the apparent x-height of fallback fonts, minimizing visual layout shifts while external assets load.
Fluid typography
Traditional fluid typography techniques calculate text size using viewport-based units such as vw. While effective for full-width page layouts, viewport units fall short within modular design systems. A heading nested inside a narrow sidebar will scale based on the width of the entire browser window rather than the space available in its immediate container, frequently resulting in excessively large text within confined components.
.article-container
container-type: inline-size;
:root
--step-0: clamp(1rem, 0.9rem + 1cqi, 1.125rem);
--step-3: clamp(2rem, 1.6rem + 3cqi, 2.75rem);
By assigning container-type: inline-size to a parent element, the layout engine establishes an inline container query context. This enables child elements to utilize cqi units—where 1cqi equals one percent of the container’s inline size—rather than relying on global viewport dimensions.
When paired with the clamp() function, container-relative units allow typography to fluidly adjust within lower and upper bounds. The same heading component can seamlessly scale across a main content column or a narrow 300-pixel sidebar without requiring component-specific media query overrides.
Vertical rhythm: trim the half-leading
In standard CSS layout models, the inline line box automatically incorporates empty vertical space above the capital letter height (cap-height) and below the baseline. This built-in space, known as half-leading, is derived from font metric parameters. While essential for preventing overlapping lines in multi-line paragraphs, half-leading presents challenges when attempting to align text precisely flush with adjacent graphic elements, structural borders, or hero containers.
Historically, developers relied on font-specific negative margins or manual CSS transforms to counter half-leading—fragile fixes that easily broke when changing font families or font sizes. Modern specifications solve this with native box trimming properties.
:heading, p, blockquote, figcaption, li
text-box-trim: trim-both;
text-box-edge: cap alphabetic;
/* shorthand: text-box: trim-both cap alphabetic; */
The text-box-trim: trim-both property explicitly strips the half-leading from both the top and bottom of the line box. Concurrently, text-box-edge: cap alphabetic defines the precise boundary measurements, trimming the box tight to the top of capital letters and the alphabetic baseline. Developers can also use the concise text-box shorthand property.
@supports selector(:heading)
:heading
text-box: trim-both cap alphabetic;
Because the CSS Working Group’s Selectors Level 5 specification proposes the broad :heading pseudo-class—which targets standard HTML heading tags h1 through h6 alongside ARIA role elements matching [role="heading"]—implementations should be wrapped in an @supports selector() check until native browser implementation is fully universal.
Balanced headlines, orphan-free paragraphs
Inconsistent line lengths and single-word line wraps (orphans) have long compromised layout composition. Traditionally, fixing these issues required client-side JavaScript scripts to inject non-breaking spaces ( ) or insert line breaks dynamic upon window resize events. Native CSS properties now provide clean, declarative solutions for line-wrapping control.
:heading, blockquote, figcaption
text-wrap: balance;
p, li, dd
text-wrap: pretty;
max-width: 65ch;
[contenteditable="true"]
text-wrap: stable;
The text-wrap: balance declaration instructs the rendering engine to evaluate and balance line lengths across multi-line text blocks. This property is optimized for short display blocks up to roughly six lines, such as headlines, blockquotes, and captions, preventing single dangling words on a final line without manual markup changes.
For longer prose, text-wrap: pretty addresses trailing orphans. Unlike balance, which re-balances the entire text block, pretty specifically evaluates the layout of the final four lines in a paragraph. It subtly adjusts line breaking to ensure that the final line contains at least two words, preserving structural efficiency across large text blocks.
In user-editable UI components, such as contenteditable elements, dynamically re-balancing text on every keypress can cause distracting layout shifts. Applying text-wrap: stable keeps existing lines stationary while new text is typed, maintaining layout predictability during content editing.
Hyphenation, properly tuned
Enabling automatic hyphenation improves text density and prevents awkward white spaces in narrow columns or justified alignment. However, basic implementation can introduce visually distracting "hyphen ladders"—where several consecutive lines terminate in hyphens—or break technical terms mid-word.
To function accurately, hyphens: auto relies entirely on correct natural language declarations within the markup. Without explicit document or element language indicators, the browser engine lacks the dictionary context required to identify valid hyphenation boundaries.
<html lang="en-GB">
p
hyphens: auto;
hyphenate-limit-chars: 6 3 3; /* word length, min before break, min after break */
hyphenate-character: "‐"; /* use proper hyphen glyph instead of dash */
hyphenate-limit-lines: 2; /* no more than 2 consecutive hyphenated lines */
hyphenate-limit-zone: 8%; /* reduce overall hyphenation frequency */
hyphenate-limit-last: always; /* never hyphenate the last word of a paragraph */
/* Safari legacy equivalents */
-webkit-hyphens: auto;
-webkit-hyphenate-limit-before: 4;
-webkit-hyphenate-limit-after: 3;
-webkit-hyphenate-limit-lines: 2;
pre, code, var, samp, kbd, :heading
hyphens: manual;
-webkit-hyphens: manual;
Fine-tuning hyphenation behavior requires specific control properties. The hyphenate-limit-chars property sets explicit length requirements: setting 6 3 3 dictates that a word must contain at least six characters to be eligible for hyphenation, with a minimum of three characters remaining before the break and three carried over to the next line.
The hyphenate-limit-lines: 2 declaration caps consecutive hyphenated lines at two, eliminating hyphen ladders. Meanwhile, hyphenate-limit-zone: 8% reduces overall breaking frequency by allowing small right-margin variance, and hyphenate-limit-last: always prevents the final word of a paragraph from breaking across lines.
Because WebKit-based browsers like Safari rely on vendor-prefixed properties for granular limits, specifying both standard and prefixed properties ensures cross-browser consistency. Crucially, code blocks, variables, and display headings should explicitly reset to hyphens: manual. Hyphenating code samples or technical syntax can alter program logic and degrade technical clarity.
Hanging punctuation and ink-aware underlines
Refining edge alignment and text decorations adds visual polish to web typography, closer matching traditional print techniques.
blockquote, p
hanging-punctuation: first allow-end last;
a
text-decoration-thickness: from-font;
text-underline-offset: 0.15em;
text-decoration-skip-ink: auto;
Punctuation characters carry less visual mass than alphanumeric glyphs. When quotation marks or brackets start a line, they can create the optical illusion of an unintended indent. The hanging-punctuation property addresses this optical imbalance.
The first keyword allows opening punctuation to sit slightly outside the structural edge of the text box. The last keyword applies the same logic to closing punctuation at the end of blocks, while allow-end permits hyphens and trailing punctuation to project beyond the right margin rather than forcing an early line break. The result is a crisp, optically flush vertical edge along body copy margins.
Default web browser link underlines historically drew a solid line directly through lower glyph forms, obscuring letters like "p", "g", and "y". Modern CSS properties resolve this by respecting font metrics:
text-decoration-thickness: from-fontadopts the underline weight defined by the typeface designer.text-underline-offset: 0.15emlowers the line, giving character descenders visual breathing room.text-decoration-skip-ink: autoautomatically skips the underline where descenders intersect it, keeping letterforms clear and readable.
Variable font fine-tuning
Variable fonts combine multiple typographic weights and styles into a single font file, offering refined visual control through standardized CSS properties.
body
font-optical-sizing: auto;
font-variant-ligatures: common-ligatures contextual;
font-kerning: normal;
/* Dark mode grade compensation */
:root
--vf-grad: 0;
@media (prefers-color-scheme: dark)
:root --vf-grad: -50;
*
font-variation-settings: "GRAD" var(--vf-grad, 0);
The font-optical-sizing: auto property allows typefaces built with an optical size (opsz) axis to dynamically adjust stroke contrasts. At smaller display sizes, character strokes subtly thicken and counters widen for improved legibility; at display sizes, strokes refine to emphasize elegant contrast. Furthermore, enabling font-variant-ligatures and setting font-kerning: normal ensures that OpenType ligatures and kerning tables apply reliably across all content.
Color schemes also affect perceived typographic weight. Light text set against a dark background visually blooms, appearing heavier than dark text set against a light background.
When utilizing variable fonts that feature a Grade (GRAD) axis, developers can adjust this optical illusion without causing layout reflows. By setting a negative grade value (--vf-grad: -50) within a prefers-color-scheme: dark media query, the browser reduces the perceived weight of the font on dark backgrounds without modifying character bounding boxes or line wraps.
@font-face
font-family: "Mono";
src: url("/fonts/mono-var.woff2") format("woff2");
size-adjust: 105%; /* tune per-font */
When combining monospace code fonts alongside primary body sans-serif or serif fonts, declared font sizes often produce mismatched x-heights. Setting the size-adjust property inside the @font-face definition allows developers to rescale the target font’s visual dimensions globally without altering standard font-size declarations in the component layer.
Numeric, emoji, and script-aware text
Numbers require different typographic treatments depending on context. Tabular displays like data tables demand fixed-width alignment, whereas body copy calls for proportional figures that match the flow of surrounding text.
table, .tabular
font-variant-numeric: tabular-nums lining-nums;
.prose
font-variant-numeric: oldstyle-nums proportional-nums;
.emoji-color
font-variant-emoji: emoji;
.emoji-mono
font-variant-emoji: text;
Applying tabular-nums forces all numbers to share uniform widths, ensuring numerical columns align cleanly in financial tables or dashboard interfaces. Combining this with lining-nums ensures digits share a uniform height matching uppercase letters.
Conversely, applying oldstyle-nums and proportional-nums to narrative prose lets digits adopt varying character widths and ascenders/descenders, allowing them to blend seamlessly with lowercase text without disrupting reading rhythm.
Platform handling of emoji glyphs can also be unpredictable. The font-variant-emoji property explicitly toggles between full-color graphic display (emoji) and flat monochrome representation (text), giving systems clear intent rather than falling back on operating system defaults.
Locale-aware quotes and native subscripts and superscripts
Quotes and typographic markers vary by region and language. For example, standard American English nests single quotes inside double quotes, British English often reverses this convention, and French typography uses guillemets separated by non-breaking spaces.
:where(:lang(en)) > * quotes: '"' '"' "'" "'";
:where(:lang(en-GB)) > * quotes: "'" "'" '"' '"';
:where(:lang(fr)) > * quotes: "«0202F" "0202F»" '"' '"';
q::before content: open-quote;
q::after content: close-quote;
By defining locale rules via the :lang() pseudo-class on the quotes property, semantic HTML <q> tags automatically insert the correct locale-specific glyphs via open-quote and close-quote pseudo-elements. Markup remains clean and localized without manually hardcoding specific characters into source templates.
Similarly, standard browser defaults render <sub> and <sup> elements by applying math calculations—artificially shrinking font size and shifting vertical alignment. This synthetic scaling often results in overly thin stroke weights that look mismatched against surrounding text.
@supports (font-variant-position: sub)
:is(sub, .sub)
vertical-align: baseline;
font-size: 100%;
line-height: inherit;
font-variant-position: sub;
@supports (font-variant-position: super)
:is(sup, .sup)
vertical-align: baseline;
font-size: 100%;
line-height: inherit;
font-variant-position: super;
When supported by the active font, font-variant-position enables true OpenType subscript and superscript glyphs designed specifically for those positions. Resetting vertical-align, font-size, and line-height back to inherit defaults allows true alternate glyphs to display with correct line bounds and stroke weights.
A note on specificity: :is() and :where()
Managing selector specificity is critical when authoring a foundational CSS reset. Reset declarations should establish baseline defaults without making it difficult for developers to override properties using utility classes or component-level stylesheets later in the build.
:where(h1, h2, h3, h4, h5, h6)
margin-block: 0.5em;
The :where() pseudo-class strips specificity entirely, evaluating to zero (0,0,0). Wrapping baseline selectors inside :where() allows utility classes or element selectors declared anywhere in the codebase to instantly override reset styles without relying on high-specificity chains or !important flags.
:is(h1, h2, h3, h4, h5, h6), p, blockquote, figcaption, li
text-box: trim-both cap alphabetic;
Conversely, the :is() pseudo-class streamlines selector lists by grouping repeated elements without duplicating code blocks. Unlike :where(), :is() inherits the specificity weight of its most specific argument. Understanding this distinction ensures stylesheets remain easy to maintain and extend.
The complete tidy-typography.css
Below is the consolidated tidy-typography.css stylesheet, combining rendering fixes, fluid container-query typography, text-wrap controls, variable font adjustments, and locale rules into a single production-ready reset.
/* ==========================================================================
tidy-typography.css — a modern typography reset
Every rule degrades gracefully in unsupported browsers.
========================================================================== */
html
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
font-synthesis: none;
-moz-text-size-adjust: none;
-webkit-text-size-adjust: none;
text-size-adjust: none;
body
max-width: 800px;
margin: 0 auto;
padding: 1rem;
/* ---- Fluid typography ---- */
.article-container
container-type: inline-size;
:root
--step-0: clamp(1rem, 0.9rem + 1cqi, 1.125rem);
--step-1: clamp(1.25rem, 1.1rem + 1.5cqi, 1.5rem);
--step-2: clamp(1.6rem, 1.35rem + 2cqi, 2rem);
--step-3: clamp(2rem, 1.6rem + 3cqi, 2.75rem);
--step-4: clamp(2.5rem, 1.9rem + 4.5cqi, 4rem);
--vf-grad: 0;
@media (prefers-color-scheme: dark)
:root
--vf-grad: -50;
/* ---- Variable font fine-tuning ---- */
*
font-variation-settings: "GRAD" var(--vf-grad, 0);
body
font-size: var(--step-0);
font-size-adjust: from-font;
line-height: 1.6;
font-optical-sizing: auto;
font-variant-ligatures: common-ligatures contextual;
font-kerning: normal;
/* ---- Text box trim ---- */
:is(h1, h2, h3, h4, h5, h6), p, blockquote, figcaption, li
text-box: trim-both cap alphabetic;
/* ---- Text wrap ---- */
:is(h1, h2, h3, h4, h5, h6), blockquote, figcaption
text-wrap: balance;
font-size: var(--step-3);
line-height: 1.15;
letter-spacing: -0.01em;
h1
font-size: var(--step-4);
p, li, dd
text-wrap: pretty;
max-width: 65ch;
hyphens: auto;
hyphenate-limit-chars: 6 3 3;
hyphenate-limit-lines: 2;
hyphenate-limit-zone: 8%;
hyphenate-limit-last: always;
pre, code, var, samp, kbd, :is(h1, h2, h3, h4, h5, h6)
hyphens: manual;
blockquote, p
hanging-punctuation: first allow-end last;
[contenteditable="true"]
text-wrap: stable;
/* ---- Numeric, emoji, and script-aware text ---- */
table, .tabular
font-variant-numeric: tabular-nums lining-nums;
.prose
font-variant-numeric: oldstyle-nums proportional-nums;
.emoji-color
font-variant-emoji: emoji;
.emoji-mono
font-variant-emoji: text;
/* ---- Locale-aware quotes ---- */
:where(:lang(en)) > *
quotes: '"' '"' "'" "'";
:where(:lang(en-GB)) > *
quotes: "'" "'" '"' '"';
q::before
content: open-quote;
q::after
content: close-quote;
/* ---- Native sub and superscripts ---- */
@supports (font-variant-position: sub)
sub, .sub
vertical-align: baseline;
font-size: 100%;
line-height: inherit;
font-variant-position: sub;
@supports (font-variant-position: super)
sup, .sup
vertical-align: baseline;
font-size: 100%;
line-height: inherit;
font-variant-position: super;
/* ---- Ink-aware underlines ---- */
a
text-decoration-thickness: from-font;
text-underline-offset: 0.15em;
text-decoration-skip-ink: auto;
What belongs in a reset
The role of a CSS typography reset has expanded. Where traditional stylesheets focuses primarily on neutralizing default margins and setting basic line height ratios, modern resets actively solve complex layout challenges that previously leaked into component templates or required runtime JavaScript scripts.
Declarations like text-wrap handle paragraph orphans directly in the browser engine, container query units keep typography components proportional to their parent layout contexts, and box trimming properties like text-box-trim clean up spatial alignment without relying on negative margin compensations. Delegating quote styling, native sub/superscript positions, and optical font sizing directly to native CSS rules reduces project code complexity and yields faster visual rendering performance.
Browser support for newly finalized specifications will continue to evolve. Unrecognized CSS properties are naturally ignored by layout engines, enabling modern stylesheets to degrade gracefully in legacy environments. Ultimately, evaluating which typography rules belong in a core reset depends on project requirements, content type, target device platforms, and specific browser support matrices.