CSS clamp() Generator

Auto-generate a CSS clamp() function from min/max values and a viewport range.

Category: Dev Tools

When to use?

Use it for fluid typography where font size or spacing smoothly changes between mobile and desktop. Just enter values and the clamp() is generated.

How to use

  • Enter the min (mobile size) and max (desktop size).
  • Enter the viewport widths where min and max apply.
  • Copy the generated clamp() expression.

Input Explanation

Enter the min font size for mobile, the max font size for desktop, and the viewport-width range these respond across.

Calculation Basis

It generates clamp(min, preferred, max), where the preferred value is a vw + rem combination linearly interpolated between the two viewport sizes.

Usage Examples

  • Generate fluid font sizes - Enter mobile and desktop font sizes to auto-generate a clamp() value.
  • Set responsive spacing - Make padding/margin clamp values that change smoothly with screen size.
  • Quick pre-deploy check - Check inputs and output to reduce errors before dev/ops work.

Examples

  • Mobile 16px (375px), desktop 24px (1440px) → clamp(1rem, 0.7rem + 1.6vw, 1.5rem)
  • Set card padding with clamp → not too tight even on small screens

Cautions

  • Generated output is for reference; test carefully before production use.
  • Specific web-standard specs or framework-only syntax may cause compatibility issues.

Guides

The CSS clamp() function

clamp(min, preferred, max) limits a value to a range. It is mainly used to auto-scale font size or spacing between a min and max by viewport.

Fluid typography

For example, clamp(1rem, 2.5vw, 2rem) is 1rem on narrow viewports, 2rem on wide ones, and 2.5vw in between — responsive sizing without media queries.

FAQ

What is CSS clamp()?

A CSS function clamp(min, preferred, max) that limits a value to a min–max range.

Can I copy the generated clamp value?

Yes, the copy button copies the clamp() expression.

How is the preferred vw coefficient decided?

By a linear equation connecting the min/max sizes and the two viewport widths, so the value changes linearly with width.

Where is clamp() mainly used?

To smoothly scale font size or spacing without media queries while preventing too-small or too-large values.

Related Tools

  • JSON Formatter - Beautify or minify JSON strings instantly and check for validity errors.
  • UUID Generator - Generate up to 20 cryptographically secure UUID v4 values at once.
  • Password Generator - Generate secure random passwords in the browser by choosing length, character set, and count.
  • JWT Decoder - Decode a JWT header and payload to view the JSON and key claims.
  • Regex Tester - Enter a regex pattern to see matches in text in real time.
  • QR Code Generator - Convert text or a URL into a QR code and download it as an image.