Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

How do min(), max() and clamp() work in CSS?

CSS
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedNov 29, 2026
5 min read

The CSS functions min(), max() and clamp() pick a value from a list at layout time. min() returns the smallest value, max() returns the largest, and clamp(minimum, preferred, maximum) returns the preferred value but never lets it go below the minimum or above the maximum. Together, the css clamp min max functions let you write responsive sizes without media queries.

This guide shows how each one resolves, the typical uses for widths and fluid typography, how they differ from min-width and max-width, and the accessibility point you must not skip when you size text.

Table of Contents

  • How min() works
  • How max() works
  • How clamp() works
  • Math inside the functions
  • Fluid typography done accessibly
  • Choosing between min-width, max-width and the functions
  • Common mistakes
  • Browser support
  • Frequently Asked Questions
    • What is the difference between min() and max-width?
    • Can clamp() be used for more than font size?
    • Why does my clamp() text not scale on zoom?
    • Can I nest min(), max() and clamp()?
  • Summary
  • Related Articles

How min() works

min() takes two or more values and returns the smallest one. Units can be mixed, and the choice is re-evaluated whenever the viewport or container changes.

css

On a wide screen, 90% of the parent is larger than 1100px, so the width is 1100px. On a narrow screen, 90% is smaller, so the width is 90%. This single line replaces width: 90%; max-width: 1100px;, and the two forms are equivalent. Think of min() as "never larger than the smallest of these".

How max() works

max() returns the largest value from the list. Think of it as "never smaller than the largest of these".

css

The first rule keeps padding at least 0.75rem, growing with the viewport after that. The second is a common mobile pattern: use at least 1rem, but more on devices with a notch where the safe area inset is larger.

How clamp() works

clamp() takes three arguments in the order minimum, preferred and maximum. It is equivalent to max(minimum, min(preferred, maximum)).

css

The size follows 1rem + 3vw while that value stays between 1.75rem and 3.5rem. Below that range the heading stays 1.75rem, above it the heading stops at 3.5rem. This is the standard recipe for fluid typography.

Viewport width (16px root)1rem + 3vwResult
320px25.6px28px (minimum, 1.75rem)
600px34px34px (preferred)
1200px52px52px (preferred)
1600px64px56px (maximum, 3.5rem)

Math inside the functions

All three functions accept math expressions directly, so you do not need to write calc() inside them. Operators follow the same spacing rules as calc(): put spaces around + and -.

css

Percentages inside these functions are resolved against the same reference as the property they appear in, so 5% in padding is relative to the containing block's width.

Fluid typography done accessibly

Using only vw for font size is an accessibility problem. Text sized purely in vw does not grow when the user zooms the page or raises the default font size, which can break WCAG requirements for resizable text. The fix is to include a rem term in the preferred value, as in 1rem + 3vw, and to use rem for the bounds.

css

A good check is to zoom the page to 200 percent and confirm that text becomes larger. If the bounds are rem based, it does.

Choosing between min-width, max-width and the functions

GoalClassic wayWith functions
Fluid with a capwidth: 90%; max-width: 1100px;width: min(90%, 1100px);
Fluid with a floorwidth: 50%; min-width: 300px;width: max(50%, 300px);
Fluid with bothThree declarationswidth: clamp(300px, 50%, 800px);
Fluid font sizeSeveral media queriesfont-size: clamp(...)

The functions shine for properties that have no min- and max- variants, such as font-size, padding, margin, gap and border-radius. For width and height, min-width and max-width remain clear and perfectly fine.

Common mistakes

  • Using clamp() arguments in the wrong order. The minimum must come first and the maximum last. If the minimum is larger than the maximum, the minimum wins.
  • Forgetting spaces around + and -. clamp(1rem, 1rem+3vw, 3rem) is invalid.
  • Using only vw for the preferred value in text, which ignores user settings.
  • Writing a media query with these functions, which is not supported in query conditions.
  • Mixing in a unitless number where a length is required, such as min(10, 5px).

Browser support

min(), max() and clamp() are supported in all current browsers, including Chrome, Edge, Firefox and Safari, and have been since 2020. No fallback is needed for modern projects. If you still support a very old browser, write a plain font-size declaration before the clamp line.

css

Frequently Asked Questions

What is the difference between min() and max-width?

width: min(90%, 1100px) and width: 90%; max-width: 1100px give the same result for width. The function form also works on properties that have no max variant.

Can clamp() be used for more than font size?

Yes. It works for any numeric value: width, height, padding, margin, gap, border radius and more.

Why does my clamp() text not scale on zoom?

The preferred value is probably pure vw. Add a rem part such as 1rem + 3vw and use rem bounds so the text responds to zoom and font settings.

Can I nest min(), max() and clamp()?

Yes. You can nest them and mix them with arithmetic, for example clamp(1rem, max(2vw, 1rem), 2rem), though simple forms are easier to read.

Summary

min() caps a value, max() sets a floor and clamp() does both around a preferred value. They accept mixed units and math without calc(), and they replace many media queries for fluid sizes. For text, keep rem in the preferred value and bounds so zoom and user font settings keep working.

Related Articles

  • How do you use calc() to do math in CSS?
  • What are the CSS display values block, inline and inline-block?
  • Learn CSS: Complete Study Roadmap from Beginner to Advanced
Share