Skip to content
Categories
CSS Clamp Calculator
Calculate a responsive CSS clamp() value from a min/max viewport width and font size.
Overview
- Calculates a CSS clamp() value that smoothly scales with viewport width, from a min/max viewport width and the corresponding min/max font size.
- Instead of switching font-size at each media query breakpoint, a single clamp() declaration achieves smoothly scaling responsive font sizes (fluid typography).
- Use the preview slider to see how the font size changes as the viewport width changes.
Usage
- Enter the viewport width range over which the font size should change into "Min/max viewport width (px)".
- Enter the font sizes, in rem, that should correspond to that range into "Min/max font size (rem)".
- Click the "Calculate" button to see the clamp() value and a preview. Drag the preview slider to see how the font size actually changes across viewport widths.
Example
Input
Min width: 375px / Max width: 1280px / Min size: 1rem / Max size: 2rem
Output
clamp(1rem, calc(0.5856rem + 0.1105vw), 2rem)
Use Cases
- Smoothly scaling heading or body font-size from mobile to desktop (fluid typography)
- Replacing per-breakpoint font-size declarations in media queries with a single clamp() declaration
- Mechanically deriving the CSS value to implement from a min/max font size specified in a design
FAQ
Why is rem the only supported font size unit? Can I use px or em?
Only rem is supported, since specifying font-size in rem — so it scales with the user's browser base font size setting — is considered an accessibility best practice.
Why is the viewport width unit px?
Responsive design breakpoints are commonly specified in px, so px was chosen for clarity.
Can the max font size be smaller than the min font size?
No. The max font size must be greater than or equal to the min font size (equal values are allowed).
Notes
- The formula is based on the common fluid typography technique of expressing a line through two points — (min viewport width, min size) and (max viewport width, max size) — using CSS calc() and the vw unit.
- Below the min viewport width the font size stays fixed at the min size, and above the max viewport width it stays fixed at the max size (this is what clamp() enforces).
- The same approach can be applied to many other CSS length properties besides font-size, such as padding and gap.
Related Tools
Convert between px, rem, em, and pt.
Generate linear-gradient or radial-gradient CSS from colors and positions.
Generate CSS Grid styles from column count, row count, and gap.