CSS Type Scale with pow()
CSS type scale with pow()
The old way required Sass or JavaScript to compute exponential type scales. pow() does the math at runtime in the browser so you control the base and ratio with custom properties.
The old hack vs the modern fix
// Sass — computed at build time, ratio is baked in
@use "sass:math";
$base: 1rem;
$ratio: 1.25;
h1 { font-size: $base * math.pow($ratio, 4); } // 2.441rem
h2 { font-size: $base * math.pow($ratio, 3); } // 1.953rem
h3 { font-size: $base * math.pow($ratio, 2); } // 1.563rem
h4 { font-size: $base * math.pow($ratio, 1); } // 1.25rem
h5 { font-size: $base * math.pow($ratio, 0); } // 1rem:root {
--scale-base: 1rem;
--scale-ratio: 1.25;
}
h1 { font-size: calc(var(--scale-base) * pow(var(--scale-ratio), 4)); }
h2 { font-size: calc(var(--scale-base) * pow(var(--scale-ratio), 3)); }
h3 { font-size: calc(var(--scale-base) * pow(var(--scale-ratio), 2)); }
h4 { font-size: calc(var(--scale-base) * pow(var(--scale-ratio), 1)); }
h5 { font-size: calc(var(--scale-base) * pow(var(--scale-ratio), 0)); }Exp functions browser support
pow() is Baseline Widely available (since 2023). Supported in Chrome 120+, Firefox 118+, Safari 15.4+, Edge 120+.
Why the modern way wins
No build step
Sass math.pow() runs at compile time. CSS pow() runs in the browser, so the values are live custom properties you can swap at runtime without rebuilding.
One variable to tune
Change --scale-ratio and every heading updates. Change --scale-base and the whole scale shifts. Two knobs, consistent math.
Composable with clamp()
Wrap each size in clamp() to add fluid scaling on top of the modular ratio. The two techniques combine without conflict.
- Key Change
- Runtime math
- Browser computes the scale
- Old Approach
- Sass or JS
- Compile-time or runtime script
- Modern Approach
- pow() + custom properties
- Live, scriptless type scale
How it works
A modular type scale sets heading sizes using a fixed ratio. If your ratio is 1.25 and your base is 1rem, h4 is 1.25rem, h3 is 1.5625rem, h2 is 1.953rem, h1 is 2.441rem. The sizes are not arbitrary — they come from multiplying the base by the ratio raised to a power.
Before pow(), you had two options. Compute the values by hand and paste them in as magic numbers, or use Sass math.pow() to compute them at build time. Either way, the ratio was baked into the output. You could not change it in the browser.
pow(base, exponent) is a CSS math function that returns a number. Inside calc(), you can use it with custom properties: calc(var(--scale-base) * pow(var(--scale-ratio), 3)). The browser evaluates it fresh every time the custom property changes, which means theming, user preferences, or JavaScript overrides work without a rebuild.