Clamp Function
ELI5 — The Vibe Check
CSS clamp() sets a value that's fluid between a minimum and maximum. clamp(1rem, 2.5vw, 2rem) means 'at least 1rem, ideally 2.5vw, but never more than 2rem.' It's responsive typography and spacing in a single line. No media queries needed.
Real Talk
The CSS clamp() function accepts three values — minimum, preferred, and maximum — and resolves to the preferred value clamped between the min and max. It's commonly used for fluid typography, responsive spacing, and flexible layouts, replacing multiple media query breakpoints with a single declaration.
Show Me The Code
h1 {
font-size: clamp(1.5rem, 4vw, 3rem);
}
.container {
padding: clamp(1rem, 3vw, 3rem);
max-width: clamp(320px, 90vw, 1200px);
}
When You'll Hear This
"clamp() for font sizes means no media queries for responsive typography" / "I use clamp() for everything now — spacing, widths, font sizes"
Related Terms
CSS (Cascading Style Sheets)
CSS is the makeup and wardrobe for your HTML skeleton. It decides what color everything is, how big things are, and where stuff goes on the page.
Media Query
A media query is a CSS if-statement based on screen conditions. 'If the screen is narrower than 768px, apply these styles.
Responsive Design
Responsive design means your website looks good on EVERY screen size — from a tiny phone to a giant 4K monitor.
Viewport
The viewport is the visible area of a webpage in the user's browser window. It changes depending on the device — small on a phone, huge on a 4K monitor.