On this page
calc()
Prev: math | Up: math | Next: `clamp()`
Rel: math, Math & Sizing Functions Guide
Ref: MDN Web Docs — calc()
Tags: #public #web #css #functions #math #tier/core
Syntax & Overview
calc(100% - 2rem)
Evaluates arithmetic (+, -, *, /) across mixed CSS units.
Notes & Best Practices
- Always put spaces around
+and-:calc(100%-2rem)is a syntax error, whereascalc(100% - 2rem)works. - Mixes relative and absolute units (
%,rem,vw,px) seamlessly.
Example
.sidebar { width: calc(100% - 2rem); max-width: calc(20ch + 4rem); }
Linked from
Related notes
- tuts/css/functions/math/clamp Linked here; links to this page; shared tags: #css, #functions, #math, #tier, #web
- tuts/css/functions/math Linked here; links to this page; shared tags: #css, #functions, #math, #web
- tuts/css/functions/math_and_sizing_functions Linked here; shared tags: #css, #functions, #web
- tuts/css/functions/math/min shared tags: #css, #functions, #math, #tier, #web
- tuts/css/functions/math/minmax shared tags: #css, #functions, #math, #tier, #web
- tuts/css/functions/math/repeat shared tags: #css, #functions, #math, #tier, #web
- tuts/css/functions/color/color-mix shared tags: #css, #functions, #tier, #web
- tuts/css/functions/color/light-dark shared tags: #css, #functions, #tier, #web
- tuts/css/functions/color/linear-gradient shared tags: #css, #functions, #tier, #web
- tuts/css/functions/color/oklch shared tags: #css, #functions, #tier, #web