calc() for Dynamic Calculations
Mix units and perform arithmetic in CSS using the calc() function for dynamic values.
calc() for Dynamic Calculations is a free CSS Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.
What is calc()?
calc() allows you to perform arithmetic directly in CSS property values. You can mix different units (px, %, rem, vw) in a single calculation.
Basic calc() Syntax
Supports addition (+), subtraction (-), multiplication (*), and division (/). Spaces around + and - operators are required.
<div class="sidebar">Sidebar (100% - 240px)</div>Mixing Units
The superpower of calc() is combining incompatible units that would otherwise be impossible to mix:
<div class="hero">Hero</div>
<div class="column">Column</div>calc() with CSS Variables
Combine calc() with CSS custom properties for dynamic design tokens:
<div class="main">Main content</div>Nested calc()
calc() can be nested, though it is rarely needed since each context already evaluates math:
<div class="element">Element</div>calc() for Fluid Typography
Use calc() to create a linear interpolation between two sizes:
<h1>Fluid Heading</h1>Division in calc()
Division requires the divisor to be a number without units:
<div class="thirds">Third width</div>calc() with Grid and Flexbox
Useful inside track definitions and flex-basis:
<div class="grid"><div>A</div><div>B</div></div>calc() vs Other Functions
When to use which:
calc(): arbitrary arithmetic, especially mixing unitsmin()/max(): pick smaller/larger of optionsclamp(): bound a fluid value between min and max
Browser Support
calc() is supported in all modern browsers and IE11. It is one of the most widely supported CSS functions. Safe to use without fallbacks in any modern project.
Common calc() Patterns
Practical patterns you will use repeatedly:
<div class="full-height">Full height minus header</div>
<div class="half-minus-gap">Half minus gap</div>
<div class="row"><div class="thirds-with-gaps">Third</div></div>Quick Check
Which calc() expression produces the correct result for "30% of parent minus 20px"?
Recap
calc() enables arithmetic in CSS with mixed units. It powers dynamic layouts like "full viewport minus fixed header" and fluid typography interpolation. Spaces are required around + and - operators. Combine with CSS variables for powerful design token math. Use alongside min/max/clamp for complete fluid sizing control.
Learn CSS with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 40
- Lessons
- 159
Frequently Asked Questions
Is the “calc() for Dynamic Calculations” lesson free?
Yes — the full text of “calc() for Dynamic Calculations” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.
What will I learn in “calc() for Dynamic Calculations”?
Mix units and perform arithmetic in CSS using the calc() function for dynamic values. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start CSS Academy?
No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “calc() for Dynamic Calculations” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this CSS Academy lesson?
Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- calc() for Dynamic Calculations
- min() max() and clamp() for Fluid Values
- repeat() and minmax() in Grid
- color-mix() and relative color syntax