Mr. Karim cuts the mat for Grandma Marni’s table: type a width with calc(), min(), max() or clamp(), the browser is the judge (what becomes of…
Why it matters
calc() is in almost every real layout: the width left after a sidebar, the screen height minus a header, a column minus a gap. And forget the spaces around -, and the browser drops the declaration without any error at all.
The key idea
calc() waits for layout to do the maths, and a - without spaces is not an operator
Common mistakes
The calc() rule is there but the width does not seem to change at all Check the spaces around + and -. calc(100%-8px) is invalid and silently dropped; write calc(100% - 8px). (* and / can go without.)
Writing long calcs to split columns evenly Even splits are cleaner with gap in flex or grid (grid-template-columns: repeat(3, 1fr)). Keep calc() for when you really need to mix units.
Thinking a percentage knows its pixels in advance A percentage is relative and only worked out at layout time, from the parent’s width then. calc() holds the px subtraction until that moment too; that is the point.
Try it in this playground
Remove the spaces yourself: calc(100%-200px) The browser drops the value and the mat shrinks to its content. Look at the tokens: -200px sticks together as one number.
Use calc(100% - var(--side)), then move --side The mat follows the scale’s corner wherever it goes, since the value comes from one variable.
Move the table’s width with a percentage value The "100% → …px" step changes with it: the percentage is worked out again from .wrap at every layout.
Try min() or clamp() E.g. min(100% - 32px, 480px): arithmetic works inside without another calc().