freecoding.school100% FREE · NO SIGNUP
Neon DistrictISSUE #9 of 50

calc() · math in values

PrismaVSJank the Janitor
Prisma sayscalc() does math across units — mix percentages, pixels, and variables in one value.

calc() computes at render time, even mixing units: width: calc(100% - 240px) for a main area beside a fixed sidebar, or calc(var(--gap) * 2). Whitespace around operators is required. It's the glue between flexible and fixed sizing.

Power-ups you unlock

Jank the Janitor attacks — common mistakes

Boss battleSize a main column as calc(100% - 200px) next to a 200px sidebar.

Example code

<!doctype html><html><head><meta charset="utf-8">
<style>.side{width:200px;float:left;background:#1c1240}.main{width:calc(100% - 200px);float:left;background:#140a28}.side,.main{color:#e6e0ff;padding:16px;box-sizing:border-box}</style></head><body style="background:#06040d;padding:20px"><div class="side">200px</div><div class="main">calc fills the rest</div></body></html>
▶ Open the interactive comic issue
‹ Var() · Fallback · ScopingMin() · Max() · Clamp() · Responsive Math ›