← Back to Overview Chapter 10: Responsive

1. The Future: Container Queries (@container)

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!

Robot
@container (min-width: 380px)

Self-Aware Component

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;
    }
}

2. Media Query Breakpoints

Your current screen size is matched live by pure CSS media queries below:

Current Viewport:
/* 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 */ }

3. Fluid Typography with clamp()

clamp(min, preferred, max) scales text smoothly based on viewport width without stepping through disjointed breakpoints.

Fluid Dynamic Typography
font-size: clamp(1.2rem, 3.5vw, 2.6rem);
/* Minimum 1.2rem, scales with 3.5% of viewport width, capped at 2.6rem */
h1 {
    font-size: clamp(1.2rem, 3.5vw, 2.6rem);
}

4. Modern Viewport Units: dvh, svh & lvh

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.

svh (Small Viewport)

Viewport height when URL address bar is expanded (smallest visible area).

lvh (Large Viewport)

Viewport height when address bar is collapsed (maximum visible area).

dvh (Dynamic Viewport)

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;
}

5. Mobile Safe Area Insets: env() (#46)

Prevent mobile notches, dynamic islands, and bottom home indicators from obscuring fixed footers using env(safe-area-inset-*).

Fixed Mobile Bar padding-bottom: env(safe-area-inset-bottom, 16px)
.fixed-mobile-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: env(safe-area-inset-bottom, 16px);
}
Fixed 🏠