Fluid Sizing with CSS Math Functions
suggest changemin(), max(), and clamp() can express responsive constraints without a series of breakpoints:
.article {
inline-size: min(calc(100% - 2rem), 70rem);
margin-inline: auto;
}
.article h1 {
font-size: clamp(2rem, 1.25rem + 3vw, 4rem);
}
.article__grid {
display: grid;
grid-template-columns: repeat(
auto-fit,
minmax(min(18rem, 100%), 1fr)
);
gap: clamp(1rem, 3vw, 2rem);
}
clamp(minimum, preferred, maximum) limits a fluid preferred value. Keep the minimum readable when users zoom, and avoid using viewport units alone for text sizing.
CSS math functions can mix compatible units. Whitespace is required around binary + and - operators when they appear in calculations.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents