CSS - Functions & Math
Overview
Quick links: Exercises • Checks • Print as PDF
Estimated time: 12–18 minutes
Use math functions to create fluid, responsive values that adapt without many breakpoints.
Learning Objectives
- Compose responsive values with
clamp()
. - Combine
calc()
with variables for powerful composition.
Details & Examples
.box{ width: calc(100% - 2rem); }
.title{ font-size: clamp(1rem, 2vw + .5rem, 2rem); }
.sidebar{ height: min(100vh, 800px); }
Try it
Checks for Understanding
- What does
clamp(min, preferred, max)
return?
Show answers
- A value constrained between min and max, often computed from the preferred expression.
Exercises
- Create a fluid type scale using
clamp()
forh1
andh2
. - Use
calc()
to create a layout that is full width minus a fixed sidebar.
Suggested answers
h1{font-size:clamp(1.75rem, 1rem + 3vw, 3rem)}
and similar forh2
..main{ width: calc(100% - 280px) }
with a 280px sidebar.