DEV Community

Cover image for What is clamp function in CSS?
sridhar02
sridhar02

Posted on

2 1

What is clamp function in CSS?

Hi everyone, today I going to explain the importance of an inbuilt CSS function called clamp() which can be used most of the time in building responsive web pages without the need of media queries.

What is a clamp function?

The clamp() CSS function clamps a value between an upper and lower bound. clamp() enables selecting a middle value within a range of values between a defined minimum and maximum.

While it’s a related idea to min() and max() it is different in specific ways:

  • Order matters
  • It only takes 3 parameters

  • Those 3 parameters are

1.The minimum

2.The target value (ideally a relative unit)

3.The maximum

Clamp function in action:

  • Font size control using a clamp() with using a single media query

  • Clamp() for controlling Image width

Resources:

If you have any doubts related to this article or anything related to tech or software-engineering in general, drop a comment here or you can message me on twitter @ksridhar02.

Neon image

Serverless Postgres in 300ms (!)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay