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:
.container {
width: 90%;
max-width: 1200px;
margin: 0 auto;
}2. Flexible Images
Images should scale within their containers:
img {
max-width: 100%;
height: auto;
}3. Media Queries
Apply different styles based on screen characteristics:
/* 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:
<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
| Approach | How it works | Media queries |
|---|---|---|
| Mobile-first | Base styles for mobile, add complexity for larger screens | min-width |
| Desktop-first | Base styles for desktop, simplify for smaller screens | max-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
/* 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
.card-container { container-type: inline-size; }
@container (min-width: 400px) {
.card { flex-direction: row; }
}CSS clamp() for Fluid Typography
h1 { font-size: clamp(1.5rem, 4vw, 3rem); }auto-fit / auto-fill Grid
.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 readyA concise answer to help you respond confidently on this topic during an interview.