On this page
clamp()
Prev: `calc()` | Up: math | Next: `min()`
Rel: math, Math & Sizing Functions Guide
Ref: MDN Web Docs — clamp()
Tags: #public #web #css #functions #math #tier/core
Syntax & Overview
clamp(1.25rem, 1rem + 2vw, 2.5rem)
Clamps a fluid preferred value between a minimum floor and maximum ceiling.
Notes & Best Practices
- Ideal for fluid typography and spacing:
clamp(min, preferred, max)smoothly scales between bounds without media-query breakpoints. - Keep a
remcomponent in the middle value (1rem + 2vw) so browser text zoom still works for accessibility.
Example
h1 { font-size: clamp(1.75rem, 1.2rem + 2.5vw, 3.25rem); }
.section { padding-block: clamp(2rem, 5vw, 5rem); }
Linked from
Related notes
- tuts/css/functions/math/calc Linked here; links to this page; shared tags: #css, #functions, #math, #tier, #web
- tuts/css/functions/math/min 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/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