Media Queries, Container Queries (@container), Modern Viewport Units (dvh) & clamp()
Unlike Media Queries (which only measure the browser window), Container Queries allow a component to style itself based on the width of its direct parent!
👉 Drag the bottom-right corner of the dashed box below to resize it and watch the layout morph dynamically!
Wider than 380px: switches to horizontal layout. Under 380px: stacks vertically!
/* Parent defines container context */
.wrapper {
container-type: inline-size;
container-name: card-container;
}
/* Child responds to its container's width! */
@container card-container (min-width: 380px) {
.card {
flex-direction: row;
text-align: left;
}
}
Your current screen size is matched live by pure CSS media queries below:
/* Mobile First Breakpoints */
@media (min-width: 640px) { /* Tablets */ }
@media (min-width: 768px) { /* Small Laptops */ }
@media (min-width: 1024px) { /* Desktops */ }
@media (min-width: 1280px) { /* Wide Displays */ }
clamp(min, preferred, max) scales text smoothly based on viewport width without stepping through disjointed breakpoints.
/* Minimum 1.2rem, scales with 3.5% of viewport width, capped at 2.6rem */
h1 {
font-size: clamp(1.2rem, 3.5vw, 2.6rem);
}
On mobile phones, the browser URL address bar and navigation bar expand and contract when scrolling, causing traditional 100vh to jump or hide content under bars.
Viewport height when URL address bar is expanded (smallest visible area).
Viewport height when address bar is collapsed (maximum visible area).
Adapts in real-time as the mobile address bar expands or collapses!
/* Full height hero section that never glitches on mobile */
.hero-full-height {
min-height: 100dvh;
}
Prevent mobile notches, dynamic islands, and bottom home indicators from obscuring fixed footers using env(safe-area-inset-*).
.fixed-mobile-footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding-bottom: env(safe-area-inset-bottom, 16px);
}