Skip to main content
Practice Problems

What is responsive web design

What is Responsive Web Design?

Responsive Web Design (RWD) is an approach to web development where a website adapts its layout and content to different screen sizes and devices — desktops, tablets, and mobile phones.


Core Principles

1. Fluid Grids

Use relative units (%, fr, vw) instead of fixed pixels:

css
.container { width: 90%; max-width: 1200px; margin: 0 auto; }

2. Flexible Images

Images should scale within their containers:

css
img { max-width: 100%; height: auto; }

3. Media Queries

Apply different styles based on screen characteristics:

css
/* Mobile first — base styles for mobile */ .sidebar { display: none; } /* Tablet */ @media (min-width: 768px) { .sidebar { display: block; width: 250px; } } /* Desktop */ @media (min-width: 1024px) { .sidebar { width: 300px; } }

The Viewport Meta Tag

Essential for mobile rendering:

html
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Without this tag, mobile browsers render the page at a desktop-like width and zoom out.

Mobile-first vs Desktop-first

ApproachHow it worksMedia queries
Mobile-firstBase styles for mobile, add complexity for larger screensmin-width
Desktop-firstBase styles for desktop, simplify for smaller screensmax-width

Mobile-first is generally recommended because:

  • Mobile traffic exceeds desktop globally
  • Forces you to prioritize essential content
  • Progressive enhancement is more robust

Common Breakpoints

css
/* Small phones */ @media (min-width: 480px) { } /* Tablets */ @media (min-width: 768px) { } /* Small laptops */ @media (min-width: 1024px) { } /* Desktops */ @media (min-width: 1280px) { } /* Large screens */ @media (min-width: 1536px) { }

Modern Responsive Techniques

CSS Container Queries

css
.card-container { container-type: inline-size; } @container (min-width: 400px) { .card { flex-direction: row; } }

CSS clamp() for Fluid Typography

css
h1 { font-size: clamp(1.5rem, 4vw, 3rem); }

auto-fit / auto-fill Grid

css
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

Important:

Responsive design is not optional — it's a requirement for modern web development. Always use the viewport meta tag, prefer relative units, and adopt a mobile-first approach for best results.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems