Skip to main content
⚡ OpenDevDocs
CSS
frontendcssGuideIntermediate

Responsive Web Design and Media Queries

Creating adaptive mobile-first layouts: @media queries, viewport breakpoints, fluid clamp() typography, and modern container queries (@container).

Verified: 2026-09-30
Platforms:
web
#css#responsive#media-queries#mobile-first#clamp#web

Responsive Web Design and Media Queries

Responsive Web Design (RWD) ensures that web applications look and function optimally across all device form factors—from mobile smartphones and tablets to high-resolution desktop monitors.


1. The Mobile-First Approach

In mobile-first design, default styles outside media queries target small mobile screens. Media queries using min-width progressively enhance the layout for wider viewports:

/* 1. Base Mobile Styles (Default) */
.container {
  padding: 1rem;
  font-size: 1rem;
}

.nav-links {
  display: none; /* Hide on mobile behind hamburger button */
}

/* 2. Tablet Breakpoint (≥ 768px) */
@media (min-width: 768px) {
  .container {
    padding: 2rem;
  }
  .nav-links {
    display: flex;
    gap: 1.5rem;
  }
}

/* 3. Desktop Breakpoint (≥ 1024px) */
@media (min-width: 1024px) {
  .container {
    max-width: 1200px;
    margin: 0 auto;
  }
}

2. Standard Industry Breakpoints

Device CategoryBreakpoint RangeTailwind Equivalent
Mobile Phones< 640pxDefault (no prefix)
Large Phones / Phablets≥ 640pxsm:
Tablets / iPads≥ 768pxmd:
Laptops / Small Desktops≥ 1024pxlg:
High-Resolution Desktops≥ 1280pxxl:
Ultra-Wide Displays≥ 1536px2xl:

3. Fluid Typography with clamp()

CSS clamp(min, preferred, max) calculates dynamic typography that scales smoothly with the viewport width without requiring multiple media query steps:

h1 {
  /* Minimum 1.75rem (28px), scales with 4vw, maximum 3.5rem (56px) */
  font-size: clamp(1.75rem, 4vw + 1rem, 3.5rem);
}

4. Modern Container Queries (@container)

While media queries check the browser viewport, Container Queries evaluate the width of the parent component:

.card-wrapper {
  container-type: inline-size;
}

@container (min-width: 400px) {
  .card-item {
    display: flex; /* Switch from vertical stack to horizontal row */
  }
}

On this page