CSS Clamp Generator

Generate CSS clamp() values.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Enter a minimum size in pixels, a preferred size in viewport-width units and a maximum size in pixels, and copy the clamp() value. It joins your three numbers; it does not work out the viewport-based slope for you.

How to use

1
Step 1
Enter the minimum in px.
2
Step 2
Enter the preferred size in vw.
3
Step 3
Enter the maximum in px, then Generate and copy.

How it works

clamp(min, preferred, max) returns the preferred value, but never less than min or more than max. A vw preferred value scales with the window width: 4vw is 4% of the viewport width. For example, on a 600px-wide window 4vw is 24px.

Worked example

Fluid text between 12px and 24px

Input
min 12, preferred 4vw, max 24
Output
clamp(12px, 4vw, 24px)
Walkthrough
Below a 300px viewport the text stays 12px, above 600px it stays 24px, and in between it scales with the width.

Limitations

  • The preferred value is vw only; calc() mixes with rem or a fixed offset are not generated.
  • It does not solve for a preferred value between two breakpoints.
  • Output is in px, which does not scale with user font-size settings; consider rem for text.

Questions

How does CSS clamp() work?
It takes a minimum, a preferred value and a maximum and uses the preferred value within those limits.
How do I make fluid typography with clamp?
Set a min and max size and a vw value that grows between them, for example clamp(12px, 4vw, 24px).
Can I use rem instead of px?
Yes, edit the generated units; the tool itself writes px.
Is clamp() widely supported?
Yes, all current major browsers support it.

Features

  • min, preferred vw, max
  • Copy-ready value
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • What Is A RESTful API?

    Traversy Media

    API context for JWT, JSON, and encoding utilities.

    Watch on YouTube
  • How base64 encoding works

    Andrew Schmelyun

    Mental model for Base64 encode/decode tools.

    Watch on YouTube
  • MDN Web Docs

    MDN

    Primary reference for web APIs these developer tools touch.

  • Base64

    MDN

    When Base64 is appropriate versus raw binary transfer.