CSS Academy · Lesson

Min Max and Clamp Functions

Use min(), max(), and clamp() for adaptive sizing that responds to container or viewport size.

Lesson 4 of 413 steps

Min Max and Clamp Functions is a free CSS Academy lesson on CoddyKit. This is lesson 4 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.

Why CSS Comparison Functions?

CSS comparison functions let you express conditional sizing without JavaScript: "use this size but never smaller/larger than these bounds." They are the core of modern fluid, responsive design.

min() Function

min() returns the smallest of a comma-separated list of values. The browser picks whichever value is smallest at the current viewport size.

<div class="container">Container width: min(800px, 90%)</div>

max() Function

max() returns the largest value. Useful for setting minimum sizes that also grow.

<p>Text sized with max(1rem, 2vw)</p>

clamp() Function

clamp(min, preferred, max) constrains a value between a minimum and maximum. The preferred value is usually fluid (like vw).

<h1>Clamped Heading</h1>

clamp() for Fluid Typography

Fluid typography with clamp() eliminates the need for multiple media query font-size overrides:

<h1>Main Heading</h1>
  <h2>Subheading</h2>
  <p>Body copy that scales fluidly with the viewport.</p>

clamp() for Fluid Spacing

Apply the same pattern to spacing for naturally responsive margins and padding:

<div class="section">Section with fluid padding</div>

min() for Containers

A safe container pattern that never exceeds a max-width and never adds horizontal scroll:

<div class="wrapper">Safe wrapper container</div>

Nesting Functions

You can nest comparison functions for complex expressions:

<p class="hero-text">Nested min/max inside clamp()</p>

calc() Combined with clamp()

Use calc() inside clamp() for precise fluid interpolation between two sizes:

<h1>Precise fluid heading</h1>

min-content max-content fit-content

CSS also has keyword size values:

  • min-content: smallest possible size without overflow
  • max-content: takes as much space as content needs
  • fit-content(): like max-content but capped at a provided limit
<span class="tag">Tag label</span>

Browser Support

min(), max(), and clamp() are supported in all modern browsers. No prefixes needed. They can be used anywhere a length, frequency, time, or number value is expected.

Quick Check

A heading uses font-size: clamp(1rem, 4vw, 3rem) on a 600px-wide viewport. What size is the font?

Recap

min() picks the smallest value, max() picks the largest. clamp(min, preferred, max) constrains a fluid value within bounds. These functions power modern fluid typography and spacing, often eliminating the need for multiple media-query overrides.

Free to start

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 “Min Max and Clamp Functions” lesson free?

Yes — the full text of “Min Max and Clamp Functions” 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 “Min Max and Clamp Functions”?

Use min(), max(), and clamp() for adaptive sizing that responds to container or viewport size. 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 4 of 4.

How long does the “Min Max and Clamp Functions” 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

  1. Absolute Units: px pt cm
  2. Relative Units: em and rem
  3. Viewport Units: vw vh dvh
  4. Min Max and Clamp Functions
← Back to CSS Academy