
Fluid Responsive Typography with CSS Calc and Viewport Units
Managing heading sizes with three or four separate @media breakpoints often causes abrupt jumps as the browser window resizes. On the other hand, setting font-size: 4vw directly breaks accessibility because pure viewport units (vw) ignore the user's browser zoom and default font-size preferences!
By combining a base rem value with a small vw factor inside calc(1.25rem + 1.5vw), headings scale smoothly across screen sizes while still honoring browser zoom and user font settings.
Example
/* Avoid: Pure vw ignores browser zoom */
h1 {
font-size: 4vw;
}
/* Prefer: Base rem + gentle vw slope inside calc() */
h1 {
font-size: calc(1.5rem + 1.8vw);
}
Input : Page headings (h1, h2) and body copy across mobile (320px) to desktop (1200px)
Output : Smoothly scaling typography that remains zoom-accessible and capped at maximum container widths.
Implementation
:root {
--font-sans: "Avenir Next", -apple-system, BlinkMacSystemFont, sans-serif;
--font-serif: "Times New Roman", Georgia, serif;
}
body {
font-family: var(--font-sans);
/* Scales gently from ~16px on mobile to ~18px on desktop */
font-size: calc(0.95rem + 0.2vw);
line-height: 1.6;
}
.article-title {
font-family: var(--font-serif);
/* Scales smoothly from ~28px on mobile to ~46px on desktop */
font-size: calc(1.5rem + 2vw);
line-height: 1.2;
margin: 0 0 20px 0;
}
/* Cap the maximum size on large monitors so headings don't grow forever */
@media (min-width: 1200px) {
body {
font-size: 18px;
}
.article-title {
font-size: 46px;
}
}
Main Point: Never use vw alone for font-size; always anchor calc() with a rem base so users who set their browser default font size to 20px or 24px still see proportionally larger text.
Credits
Photo by Aaron Burden