CSS Clamp
cassidoo.co·3d
🎬CSS Animation
Preview
Report Post

It’s Blogvent, day 4, where I blog daily in December!

CSS clamp() is cool and you should use it.

In a sentence, clamp() lets you assign a value to a CSS property between a minimum and a maximum range, and uses a preferred value in that range. It’s really helpful for responsive layouts and typography!

Syntax

clamp() has three parameters, in order:

  • A minimum value
  • A preferred value
  • A maximum value

You can assign it to a property, like so:

.my-column {
width: clamp(200px, 40%, 400px);
}

The column width here is always between 200px and 400px wide, and defaults to 40% of its container width. If that 40% is less than 200px, the width will be 200px. Similarly, if that 40% is more than 400px, the width will be 400px.

Or, another example:

.my-spe...

Similar Posts

Loading similar posts...