CSS Clamp Generator

Make text or spacing grow smoothly between two screen widths without writing media queries. Enter the smallest and largest size and the screen widths they apply to.

CSS Clamp Generator

Website Tools

Runs locally in your browser.

Generate fluid clamp() expressions for responsive typography. Runs locally.

Fluid typography preview — resize window

CSS

About the CSS Clamp Generator

In the past, responsive typography meant writing media queries that targeted specific screen sizes. A heading may be 24px on mobile, 32px on tablets, and 48px on desktop. However, this creates an inconsistent and fragmented reading experience where the text size jumps from one value to another abruptly. Fortunately, modern CSS provides a clamp() function that allows us to define a range within which our text will smoothly scale from a minimum size to a maximum size. However, finding the optimal value that sits in between can require some heavy math.

This CSS Clamp Generator does all the math for you so you can focus on building stunning responsive websites. Simply enter the minimum and maximum size you want, and the viewport breakpoints, and let the tool do the math to find the right fluid value for you. From typography to padding, this tool lets you create CSS clamp expressions with confidence.

Key Features of CSS Clamp Generator

  • Instant Math CalculationThe tool does the math to find the right slope equation that combines both viewport units (vw) and pixels (px) and outputs a valid CSS clamp() function.
  • Multi-Property SupportWhile the clamp function is often used for fluid typography, you can also use it for other properties such as padding or width. The Property dropdown lets you choose which CSS property you want to apply the clamp expression to.
  • Live Resizing PreviewSee how your clamp font-size behaves on the fly by resizing your browser window. The Fluid typography preview box lets you see how your text will look as you make adjustments to the tool.
  • No Server RequestsEverything happens locally in your browser. There’s no waiting for the tool to communicate with a server, saving you time and bandwidth.
  • One-Click Code ExportThe code is generated instantly as you type. The Copy CSS button lets you copy the CSS code directly to your clipboard. You can also download it as a file.

How to Use CSS Clamp Generator

  1. To begin, enter the smallest size you want your elements to be in the "Minimum font size (px)" box. Next, enter the largest size you want your elements to be in the "Maximum font size (px)" box. Then define what viewport width the scaling should begin and end at by entering values in the Viewport min and Viewport max fields. Select the CSS Property you want to apply the scaling to and the Preferred unit from the dropdown menu. Resize your browser window to see how the font-size changes as the viewport width changes in the Fluid typography preview area. Finally, click the Copy CSS button to copy the CSS code to your clipboard.

CSS Clamp Generator Examples

A font size that grows from 16px to 32px between viewports of 320px and 1200px.

Input
Minimum: 16px
Maximum: 32px
Viewport: 320px to 1200px
Result
.element {
  font-size: clamp(16px, 1.818vw + 10.18px, 32px);
}

CSS Clamp Generator — Frequently Asked Questions

What is CSS clamp()?
clamp() is a CSS function that accepts three values. The first value is the minimum size, the second value is the preferred size (usually a combination of vw and px), and the third value is the maximum size.
Why should I use clamp instead of media queries?
Media queries are useful, but they can lead to a poor typography experience for the end user since the font-size can abruptly increase or decrease at predetermined breakpoints. Clamp provides a smooth transition between two sizes while also being less verbose.
Why is the middle value in the clamp function so complex?
The middle value in the clamp function determines the slope of the line along which the font-size increases. To determine this value, we need to find a linear equation that passes through two points: (viewport_min, font_size_min) and (viewport_max, font_size_max). This is why the value can appear so complex as it is a combination of px (a fixed size) and vw (a relative size).