CSS chapters

Chapter 6 of 17

Calculations and bounded sizes

Try this in our CSS Compiler →

The idea

calc() combines compatible CSS values, including percentages and lengths. Whitespace around plus and minus is required. min(), max() and clamp() choose among calculated sizes. These functions compute property values; they do not run a program or read stdin.

Worked example

button { width: min(100%, 320px); }
main { width: calc(100% - 32px); max-width: 800px; margin: auto; }

What to check

The button is capped at 320px while staying within its containing block. The main width reserves 32px total, not 32px on each side.

Practice task

Build a content region with a maximum width and side space. Resize the preview and look for horizontal overflow.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on