OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 40

CSS Clamp, Min, and Max Functions

By Ratan Updated: 15 Oct 2026

Create fluid typography and dynamic sizing bounds using clamp(), min(), and max().

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Make a value fluid within useful limits

min, max and clamp let CSS compare compatible calculated values. They are useful for fluid text and container sizing without many closely spaced breakpoints. Keep the minimum and maximum tied to readability and layout constraints.

.article { width: min(90%, 65rem); margin-inline: auto; }
.hero-title { font-size: clamp(1.75rem, 1rem + 3vw, 3.5rem); }
.section { padding-inline: max(1rem, 4vw); }

min chooses the smaller result: the article never exceeds either 90% of its containing block or 65rem. max chooses the larger, giving section padding a floor. clamp bounds the preferred middle expression between a minimum and maximum.

Reason through clamp

In the heading example, a small viewport uses at least 1.75rem. The preferred expression grows with viewport width. A large viewport stops growth at 3.5rem. Adding a rem component avoids making the text depend solely on viewport width, but you must still test user text resizing and browser zoom.

Units and syntax

Compatible length expressions can mix units inside these math functions. Operators such as + and - need appropriate whitespace. Do not put a smaller maximum than minimum and assume the browser will guess your intended design; write a coherent range and test it.

Fluid does not mean overflow-proof

A clamp-controlled heading can still overflow because of an unbreakable word, a fixed-width child or a narrow container. Use sensible wrapping and allow natural height. Test the longest real title rather than a short placeholder.

Exercises

  1. Create a title that scales from 1.5rem to 3rem and inspect intermediate widths.
  2. Use min to limit a card's width while leaving a viewport margin.
  3. Compare max-based padding with a rigid 16px padding at wide sizes.
  4. Zoom to 200% and verify no text is clipped by a fixed-height wrapper.

हिन्दी संकेत: clamp में minimum, preferred और maximum तीनों की भूमिका अलग है। Fluid sizing को real content और zoom के साथ जांचें।

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat