What is a CSS Height Clamp()?
The clamp() function lets an element's height scale fluidly between a minimum and maximum value based on the viewport size, instead of jumping between fixed sizes at media query breakpoints.
Example:
height: clamp(180px, calc(120px + 18.75vw), 240px);In this example the element never shrinks below 180px or grows past 240px, scaling smoothly in between. This tool is part of the free ClampGenerator toolkit.
Common Use Cases for Height Clamp()
- ✅ Hero sections and banners that scale gracefully across devices
- ✅ Media and image containers that keep a sensible aspect within limits
- ✅ Cards and rows that need a comfortable minimum height without hard breakpoints
- ✅ Sticky headers or navbars that shrink on scroll without a layout jump
height, min-height & max-height
height— a self-contained fluid size.min-height— a floor for content-driven or flex/grid elements.max-height— a ceiling so a fluid or percentage-based element never grows too tall.
👉 Switch between them using the property buttons above the calculator.
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 —
height: clamp(...); - CSS Variable —
--hero-height: clamp(...); - SCSS —
$hero-height: clamp(...); - Tailwind —
'hero-height': 'clamp(...)',ready to paste intotailwind.config.js
Using Height clamp() Carefully
vhincludes mobile browser chrome. On phones,100vhis based on the largest possible viewport state and can overshoot the visible area when the address bar is showing. Usedvh(dynamic viewport height) for full-bleed mobile sections instead.heightandaspect-ratiocan conflict. If both are set on the same element, only one dimension stays auto-derived from the other — decide which one should drive the layout.- Percentage height needs a sized ancestor. A percentage-based
heightonly resolves if the parent element itself has a definite height — otherwise it computes toauto. heighthas no effect on non-replaced inline elements, same rule aswidth— setdisplay: block,inline-block, orflexfirst.- Prefer
block-sizefor logical, writing-mode-aware layouts. Try the dedicated Block-Size Clamp Generator to generate it directly.
Height Clamp Generator FAQs
How does height clamp() help in responsive design?
It allows an element to resize between a defined minimum and maximum height, adapting seamlessly to various viewport sizes without writing a single media query.
What's the difference between height, min-height, and max-height with clamp()?
height sets a fluid, self-contained size. min-height sets a floor a flexible element will never shrink below. max-height sets a ceiling for content-driven or percentage-based elements. All three accept the same clamp() output from this tool.
Should I use vh or dvh for a height clamp()?
vh is fine for most desktop layouts, but on mobile it's based on the largest possible browser UI state and can leave a gap when the address bar is visible. dvh (dynamic viewport height) adjusts live as mobile browser chrome shows or hides — better for full-bleed mobile sections.
Can I use this height clamp generator for hero sections and banners?
Yes — height clamp() is ideal for hero sections, banners, media, and cards that need to shrink on mobile and grow on desktop without hard breakpoints.
Can I export the height clamp value as a CSS variable, SCSS, 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.
Is this height clamp generator free to use?
Yes, it's completely free with no login required, and works offline once the page has loaded.
Need width, margin, padding, or gap too?
Use our all-in-one Layout & Spacing Clamp Generator, which covers those properties alongside height in a single tool.
Related Tools
- Width Clamp Generator
- Block-Size Clamp Generator (logical height)
- Layout & Spacing Clamp Generator
- ClampGenerator Homepage