:root { --text-xs: clamp(0.64rem, 0.5867rem + 0.237vw, 0.8rem); --text-sm: clamp(0.8rem, 0.7333rem + 0.2963vw, 1rem); --text-base: clamp(1rem, 0.9167rem + 0.3704vw, 1.25rem); --text-lg: clamp(1.25rem, 1.1458rem + 0.463vw, 1.5625rem); --text-xl: clamp(1.5625rem, 1.4323rem + 0.5787vw, 1.9531rem); --text-2xl: clamp(1.9531rem, 1.7904rem + 0.7234vw, 2.4414rem); --text-3xl: clamp(2.4414rem, 2.238rem + 0.9042vw, 3.0518rem); --text-4xl: clamp(3.0518rem, 2.7974rem + 1.1303vw, 3.8147rem); }
CSS Clamp() Generator — Fluid Responsive Typography
What's included
Features
About this tool
Generate a Fluid Type Scale With CSS clamp() — No Media Queries, Export as CSS Vars, Tailwind, or SCSS
You need responsive typography that scales smoothly between mobile and desktop — not a fixed font size that jumps between two breakpoints with a @media query. clamp() is the CSS solution: it linearly interpolates between a minimum and maximum size based on viewport width, producing smooth scaling with no layout jumps. This tool calculates the complete formula and outputs a full 8-step scale (xs through 4xl) in one click.
Set four inputs — min base size, max base size, min viewport width, max viewport width — pick a type scale ratio, and the tool generates eight fluid clamp() expressions that form a proportional typographic system. The math: slope = (maxSize − minSize) / (maxViewport − minViewport), preferred = intercept + slope × 100vw, clamp(minSize, preferred, maxSize). You don't need to do this by hand — the Formula panel shows every step of the calculation for any selected size so you can understand and verify it.
Six scale ratio presets — Minor Third (1.2), Major Third (1.25), Perfect Fourth (1.333), Augmented Fourth (1.414), Perfect Fifth (1.5), Golden Ratio (1.618) — plus a custom input. A visual viewport slider lets you preview all eight font sizes at any width between your min and max. Export as CSS custom properties (--text-xs through --text-4xl), a Tailwind fontSize config object for tailwind.config.js, or SCSS variables.
Step by step
How to Use
- 1Set the viewport rangeIn the Viewport Range section, set Min viewport to the smallest screen you support — 360px works for modern Android phones. Set Max viewport to your widest desktop breakpoint — 1440px is the most common choice. These two values define the window over which all font sizes scale linearly. Values outside this range are clamped to the fixed min or max size.
- 2Set the base font size rangeIn the Base Font Size section, set Min to your desired body font size at the minimum viewport (typically 16px) and Max to the size you want at the maximum viewport (typically 18–20px for body text). The Root font size field (default 16px) is used only for rem conversion — set it if your document uses a non-default
html { font-size: ... }value. - 3Choose a type scale ratioOpen the Type Scale dropdown and select a ratio. Major Third (1.25) is the default and works well for most UI design systems — clear but not dramatic size jumps. Perfect Fourth (1.333) suits editorial or marketing sites that need a bold heading hierarchy. Golden Ratio (1.618) creates very large jumps for display typography on landing pages. Select Custom to enter any ratio from 1.01 to 3.
- 4Choose rem or px outputToggle between
remandpxoutput.remis strongly recommended for accessibility: it scales proportionally if the user changes their browser default font size, satisfying WCAG 1.4.4 (Resize Text, Level AA).pxoutput ignores browser font preferences and is appropriate only when you have specific technical requirements for fixed pixel values. - 5Preview at any viewport widthIn the Preview pane, drag the Viewport slider left (toward your minimum) to simulate mobile, or right (toward your maximum) to simulate a wide desktop. All eight font sizes — xs, sm, base, lg, xl, 2xl, 3xl, 4xl — update live with actual rendered text and a px badge showing the exact computed size at that viewport. Click any size row to see the full slope/intercept formula derivation for that step in the Formula panel.
- 6Export the generated scaleSwitch between the CSS Vars, Tailwind, and SCSS tabs in the output panel. CSS Vars outputs a
:root { }block with--text-xsthrough--text-4xlcustom properties. Tailwind outputs atailwind.config.jsfontSizeobject ready to paste intotheme.extend.fontSize. SCSS outputs$text-xsthrough$text-4xlvariable declarations. Click Copy to copy the output.
Real-world uses
Common Use Cases
@media (max-width: 768px) { h1 { font-size: 2rem; } } style rules, replace them with a single clamp() value. Set min/max viewport widths to match your breakpoints and min/max sizes to your two values — the clamp() output replaces both rules.Got questions?
Frequently Asked Questions
Use CSS clamp() with a viewport-relative preferred value. The syntax is clamp(minimum, preferred, maximum). The preferred value uses vw units so the font scales proportionally with viewport width. Below the minimum viewport it stays fixed at the minimum size; above the maximum viewport it stays at the maximum size. This creates smooth, linear scaling between two breakpoints with a single value — no @media queries needed. This generator calculates the formula automatically: you set min size, max size, min viewport, and max viewport, and get the complete clamp() expression to paste.
The clamp() preferred value uses linear interpolation. Given minimum font size, maximum font size, minimum viewport, and maximum viewport: slope = (maxSize − minSize) / (maxViewport − minViewport). The y-intercept is: intercept = minSize − (slope × minViewport). The preferred value is: intercept + slope × 100vw. The full expression: clamp(minSize, intercept + slope×100vw, maxSize). At the minimum viewport this resolves to exactly minSize; at the maximum viewport it resolves to exactly maxSize. The Formula panel in this tool shows every step of this calculation for any selected size in the scale.
A type scale ratio is a multiplier applied to a base font size to generate a harmonious progression of sizes. Minor Third (1.2) creates subtle, compact size differences good for dense interfaces. Major Third (1.25) balances variety and subtlety — the most common choice for UI design systems. Perfect Fourth (1.333) creates bolder contrasts good for editorial layouts. Perfect Fifth (1.5) and Golden Ratio (1.618) produce dramatic jumps used for display typography and landing pages. Use the viewport slider to preview how each ratio affects your heading hierarchy before committing.
Rem is strongly preferred over px for accessibility. When a user changes their browser's default font size (a common accommodation for low-vision users), rem-based sizes scale proportionally while px sizes stay fixed. WCAG 1.4.4 (Resize Text, Level AA) requires text can be resized to 200% without loss of functionality. Using rem in clamp() satisfies this because the min and max values scale with the user's root preference. The generator outputs rem by default and shows the rem conversion alongside pixel values in the formula panel.
Set min base size, max base size, min viewport, max viewport, and a scale ratio — then click generate. The tool produces all eight sizes (xs, sm, base, lg, xl, 2xl, 3xl, 4xl) as a proportional system in a single operation. Every size is derived from the same ratio so the relationships feel natural. Export as CSS custom properties, Tailwind fontSize config, or SCSS variables — updating the entire system's typography then only requires changing two numbers.
The minimum viewport should represent your smallest supported device — typically 360px for modern Android phones. The maximum viewport should be your largest common desktop breakpoint — 1440px is the most common choice and covers most laptop and desktop displays. A 360px–1440px range gives a 1080px scaling window with smooth, perceptible font growth across the most common device sizes. Below the minimum the font stays fixed at the min size; above the maximum it stays at the max size.
Paste the CSS output into a :root { } block in your global stylesheet. Then use the variables anywhere: h1 { font-size: var(--text-4xl); }, p { font-size: var(--text-base); }. For Tailwind, paste the fontSize object into tailwind.config.js under theme.extend.fontSize — your existing text-xl, text-2xl classes then output fluid clamp() values. For SCSS, use the $text-base, $text-lg variable names in your component stylesheets after importing the variables file.
Drag the Viewport slider left to simulate a mobile screen (360px) or right to simulate a wide desktop (1440px). All eight font sizes update in real time showing both live text rendering and the exact computed pixel size. This lets you verify that sizes like 3xl and 4xl aren't too overwhelming on mobile or too small on desktop before committing to the values.