What is a CSS Width Clamp()?
The clamp() function lets an element's width scale fluidly between a minimum and maximum value based on the viewport size, instead of jumping between fixed sizes at media query breakpoints.
Example:
width: clamp(320px, calc(203.636px + 36.364vw), 640px);In this example the element never shrinks below 320px or grows past 640px, scaling smoothly in between. This tool is part of the free ClampGenerator toolkit for building fluid, responsive interfaces without media queries.
Width, Min-Width & Max-Width Clamp Generator
Easily generate fluid clamp() values for element width—perfect for cards, sections, images, or any container that needs to scale gracefully across screen sizes.
width— a self-contained fluid size.min-width— a floor for flex/grid items or percentage-based widths.max-width— a ceiling so a fluid or percentage-based element never grows too wide.
👉 Switch between them using the property buttons above the calculator.
Common Use Cases for Width Clamp()
- ✅ Content containers that stay readable on mobile and comfortable on desktop
- ✅ Cards and grid items that resize without extra breakpoints
- ✅ Hero images and media that scale proportionally with the layout
- ✅ Modals and dialogs that avoid feeling cramped or oversized
Live Preview for Width, Min-Width & Max-Width
Whichever of the three you pick, a live preview appears below the inputs with a slider that simulates a viewport width across your configured min/max range—no need to actually resize your browser. The dashed frame represents the simulated viewport and the solid bar inside represents the resulting value, both scaled by the same factor so the proportion on screen is accurate. A rough device label (📱 Mobile / 📲 Tablet / 🖥️ Desktop) shows next to the slider as a guide, based on common breakpoints—your own configured min/max viewport values still drive the actual calculation.
Export as CSS Variable, SCSS, or Tailwind
The generated code isn't limited to a plain CSS declaration. Choose an output format above the code box:
- CSS —
width: clamp(...); - CSS Variable —
--card-width: clamp(...); - SCSS —
$card-width: clamp(...); - Tailwind —
'card-width': 'clamp(...)',ready to paste intotailwind.config.js
Edit the name field to control the variable or config key used—no need to hand-edit the copied snippet afterward.
Using Width clamp() Carefully: 6 Things to Watch For
clamp() removes the need for media queries, but it's still real CSS with real edge cases. A few things worth checking before you ship a width clamp():
- Avoid
100vwas your max viewport-relative unit on full-bleed elements.vwincludes the scrollbar's width, sowidth: clamp(..., 100vw, ...)on a block that reaches the edge can trigger a horizontal scrollbar. Cap the max at something like98vw, or size against a wrapper instead of the raw viewport. widthonly affects block-level and replaced elements. A plain<span>or other inline element ignoreswidthentirely—setdisplay: inline-block,block,flex, or similar first.- Check
box-sizing. With the defaultcontent-box, padding and border are added on top of your clamp() value, so the element ends up wider than expected. Most resets already applybox-sizing: border-boxglobally—confirm yours does if the rendered size looks off. - Flex and grid items need an explicit
min-width. Flex/grid items default tomin-width: auto, which can silently override awidthclamp() and cause overflow with long unbroken text or images. Pair yourwidthclamp() with amin-widthclamp() (ormin-width: 0) on flex/grid children. - Prefer
inline-sizeoverwidthfor logical, writing-mode-aware layouts. If the design needs to work in RTL languages or vertical writing modes, swap the property toinline-size(see the MDN docs)—the clamp() value itself doesn't need to change. Try the dedicated Inline-Size Clamp Generator to generate it directly. - Provide a fallback for very old browsers. clamp() has near-universal support today, but if you must support something ancient (pre-2020 Safari/Edge), declare a plain
widthvalue before the clamp() line—CSS uses the last valid declaration, so modern browsers will still pick up the clamp() one and older browsers fall back gracefully.
Width Clamp Generator FAQs
How does width clamp() help in responsive design?
It allows an element to resize between a defined minimum and maximum width, adapting seamlessly to various viewport widths without writing a single media query.
What's the difference between width, min-width, and max-width with clamp()?
width sets a fluid, self-contained size. min-width sets a floor that a flexible element (like a flex or grid item) will never shrink below. max-width sets a ceiling so a fluid or percentage-based element never grows past a limit. All three accept the same clamp() output from this tool.
Can I use this width clamp generator for containers and cards?
Yes—width clamp() is ideal for containers, cards, modals, and content wrappers that need to shrink on mobile and grow on desktop without hard breakpoints.
What viewport unit should I use for a width clamp()?
vw (viewport width) works for most layouts. If the element sits inside a sized container rather than scaling with the whole page, switch to a container query unit like cqi or cqw, and the live preview will scale with the container instead of the browser window.
Can I export the width clamp value as a CSS variable, SCSS variable, or Tailwind config?
Yes. Switch the output format above the code box to CSS Variable, SCSS, or Tailwind, and edit the name field to control the variable or config key used in the generated snippet.
How does the live preview work?
Drag the slider to simulate any viewport width in your configured range, and the preview updates instantly using the exact clamp() value the tool generates—no need to physically resize your browser window. It works for width, min-width, and max-width.
Is this width clamp generator free to use?
Yes, it's completely free with no login required, and works offline once the page has loaded.
Need height, margin, padding, or gap too?
Use our all-in-one Layout & Spacing Clamp Generator, which covers those properties alongside width in a single tool.
Any gotchas when using width clamp() in production?
A few: 100vw can trigger a horizontal scrollbar on full-bleed elements (scrollbar width is included), width has no effect on inline elements, box-sizing changes how padding/border affect the final size, and flex/grid items need an explicit min-width since they default to min-width: auto. See the 'Using Width clamp() Carefully' section below for details.
Related Tools
- Inline-Size Clamp Generator (logical width)
- Layout & Spacing Clamp Generator (height, margin, padding, gap)
- Font Size - Typescale Clamp Calculator
- ClampGenerator Homepage