CSS clamp() Fluid Typography Generator
Generate a responsive CSS clamp() value that scales smoothly between a minimum and maximum size across a viewport range.
Result
- clamp() in rem (recommended)clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem)
- clamp() in pxclamp(16px, 13.333px + 0.8333vw, 24px)
- Preferred (fluid) term0.8333rem + 0.8333vw
- Slope (px per px of viewport)0.008333
- Range16px @ 320px โ 24px @ 1,280px
Step-by-step
- Slope = (maxSize โ minSize) รท (maxVw โ minVw) = (24 โ 16) รท (1,280 โ 320) = 0.008333 px/px.
- Y-intercept = minSize โ slopeยทminVw = 13.333px = 0.8333rem; vw coefficient = slopeร100 = 0.8333vw.
- Result: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem).
How to use this calculator
- Enter the minimum and maximum sizes (in px).
- Enter the viewport widths where scaling should start and stop.
- Keep root font size at 16 unless your project differs.
- Copy the generated clamp() value into your CSS.
About this calculator
The CSS clamp() function lets a value scale smoothly between a minimum and a maximum as the viewport changes โ perfect for fluid typography that grows from mobile to desktop without media-query jumps. clamp(MIN, PREFERRED, MAX) returns the preferred value, but never below MIN or above MAX. The trick is building the PREFERRED term so the size hits exactly your minimum at the small viewport and your maximum at the large one: that is a straight line, computed as a constant (the y-intercept) plus a vw-based slope. This generator does that math from your min/max sizes and min/max viewport widths, outputting a ready-to-paste clamp() in both rem (recommended for accessibility, since it respects user font-size settings) and px. Below the minimum viewport the size locks at the minimum; above the maximum it locks at the maximum; in between it interpolates linearly.
How it works โ the formula
slope = (maxSize โ minSize) / (maxVw โ minVw)
yIntercept = minSize โ slope ยท minVw
clamp(minSize, yIntercept + slopeยท100 vw, maxSize)A line through the two size/viewport points defines the fluid term; clamp() bounds it to the min and max.
Worked examples
- Inputs:
- minSize=16, maxSize=24, minVw=320, maxVw=1280
- Output:
- clamp(1rem, 0.833rem + 0.833vw, 1.5rem)
- Inputs:
- minSize=14, maxSize=18, minVw=360, maxVw=1440
- Output:
- clamp(0.875rem, ... + ...vw, 1.125rem)
- Inputs:
- minSize=20, maxSize=48, minVw=320, maxVw=1200
- Output:
- large fluid heading
Limitations
- Linear interpolation only (no easing curve).
- rem conversion assumes the root font size you enter.
- Very steep slopes can scale uncomfortably fast โ preview in a browser.
Generates standard CSS; verify rendering across target browsers.