CSS · CSS Tutorial · Lesson 41
CSS Math Functions
calc(), min(), max() and clamp().
CSS math functions let you use mathematical expressions as property values.
Example
<style>
.calc { width: calc(100% - 100px); background: lightblue; padding: 8px; }
.max { width: max(50%, 250px); background: lightsalmon; padding: 8px; margin-top: 8px; }
.min { width: min(50%, 250px); background: khaki; padding: 8px; margin-top: 8px; }
h1.clamp { font-size: clamp(1.2rem, 4vw, 3rem); }
</style>
<div class="calc">calc(100% - 100px)</div>
<div class="max">max(50%, 250px)</div>
<div class="min">min(50%, 250px)</div>
<h1 class="clamp">clamp() responsive heading</h1>
| Function | Returns |
|---|---|
| calc() | The result of a calculation, mixing units |
| min() | The smallest value |
| max() | The largest value |
| clamp(min, preferred, max) | A value between a minimum and maximum |
Keep reading “CSS Math Functions”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.