Difficulty: Intermediate
How do you implement responsive design, and what does a mobile-first approach mean in practice?
Responsive design means one codebase whose layout, typography and media adapt to any screen size, from a ₹8,000 Android phone to a 27-inch monitor. Mobile-first means you write the base CSS for the smallest screen and then add min-width media queries that layer on complexity as space grows, instead of building for desktop and stripping things away.
<meta name="viewport" content="width=device-width, initial-scale=1">. Without it mobile browsers render the page at roughly 980px wide and zoom out, so your media queries never fire as expected.fr units, max-width and flex or grid instead of fixed pixel widths.clamp(1.5rem, 4vw + 0.5rem, 3rem) scales smoothly between a minimum and a maximum.srcset/sizes and <picture> so a phone does not download a 2,400px hero image.| Mobile-first | Desktop-first | |
|---|---|---|
| Base styles target | Small screens | Large screens |
| Queries use | min-width | max-width |
| CSS flow | Add columns and features | Undo and hide things |
| Small devices download | Only what they need | Desktop rules plus overrides |
Most Indian users browse on phones over variable mobile networks, so starting from the constrained case forces you to prioritise content and keeps the base stylesheet lean. Simple single-column styles are also the natural default for block layout; you only add grid columns when there is room.
Common frameworks use Tailwind's 640 / 768 / 1024 / 1280 / 1536px or Bootstrap's 576 / 768 / 992 / 1200 / 1400px. Treat these as a starting point. Resize the browser slowly and add a breakpoint where line lengths get too long, cards get squashed or navigation wraps. Modern range syntax @media (width >= 768px) works in all current browsers and reads more clearly than min-width.
width: 1200px instead of max-width: 1200px with width: 100%100vh for full-height sections on mobile; prefer 100dvh or 100svh so the address bar does not hide content@media (hover: hover)display: none while it still downloads heavy imagesTest with DevTools device mode, then on at least one real low-end Android phone and one iPhone, because emulators do not reproduce slow CPUs or real touch behaviour.
<head>
<meta charset="utf-8">
<!-- Required: match the layout viewport to the device width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Never add maximum-scale=1 or user-scalable=no:
it blocks pinch-zoom and fails accessibility checks -->
</head>
This single line is what makes media queries behave on phones. Disabling zoom is a common mistake that hurts low-vision users.
/* Base: phones, no media query */
.container { padding: 1rem; }
.products {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
h1 { font-size: clamp(1.5rem, 4vw + 0.5rem, 3rem); }
/* Tablets and up */
@media (width >= 768px) {
.container { padding: 2rem; }
.products { grid-template-columns: repeat(2, 1fr); }
}
/* Laptops and up */
@media (width >= 1024px) {
.container { max-width: 1200px; margin-inline: auto; }
.products { grid-template-columns: repeat(4, 1fr); }
}
/* Full-height hero that respects mobile browser UI */
.hero { min-height: 100svh; }
/* Hover effects only where hover exists */
@media (hover: hover) {
.product:hover { transform: translateY(-2px); }
}
Each breakpoint only adds rules, so phones parse the simplest version. clamp() removes the need for separate font sizes at every breakpoint.
Mobile-first, Media queries, Viewport meta tag, Fluid layout, clamp(), Responsive images