Fluid sizing with CSS functions
W3C CSS Snapshot 2026
Use CSS functions to combine units, set a maximum width, or let a heading grow within a range as the screen gets wider.
On this page
Combine and compare lengths
calc() calculates a value from an expression such as 100% - 2rem. min() chooses the smaller result, letting a panel fit a narrow space while capping its width on large screens.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Combine and compare lengths</title>
<style>
main { box-sizing: border-box; inline-size: min(calc(100% - 2rem), 36rem); margin-inline: auto; padding: 1rem; border: 1px solid teal; }
</style>
</head>
<body>
<main>Workshop schedule</main>
</body>
</html>
What to expect On a narrow screen, the centered panel leaves space on both sides. On a wide screen, it stops growing at 36rem.
Keep a fluid font size within limits
clamp(minimum, preferred, maximum) uses the preferred value when it is within the bounds. Use a relative unit alongside a viewport unit in the preferred value and test the result with zoom.
How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Keep a fluid font size within limits</title>
<style>
h1 { font-size: clamp(1.5rem, 1rem + 3vw, 3rem); }
p { font-size: 1rem; }
</style>
</head>
<body>
<h1>Workshop schedule</h1><p>Find your next session.</p>
</body>
</html>
What to expect Resize the browser. The heading adjusts between 1.5rem and 3rem, while the paragraph remains 1rem.