Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →

Responsive Web Design Interview Questions: Media Queries, Units, Images and Mobile-First

12 responsive web design interview questions with code: the viewport meta tag, mobile-first vs desktop-first, media queries and breakpoints, rem vs em vs px, viewport units and dvh, clamp() for fluid typography, responsive images with srcset and picture, container queries, touch targets and testing.

Sumit KumarUpdated Oct 12, 20267 min readCSS
Responsive Web Design Interview Questions: Media Queries, Units, Images and Mobile-First

Most web traffic comes from phones, so every frontend interview checks whether you can build pages that work on any screen size. These 12 responsive web design interview questions cover the concepts, CSS features and image techniques you need, with examples.

Mobile-first responsive design steps: add the viewport meta tag, write base styles for small screens, add min-width breakpoints, use fluid units like rem, percent and clamp, and serve responsive images and media

Foundations#

Q1. What is responsive web design?#

Answer: responsive design means one codebase whose layout adapts to the screen it's viewed on. It rests on three ideas from Ethan Marcotte's original definition:

  1. Fluid layouts that use relative units instead of fixed pixel widths.
  2. Flexible media: images and videos that scale within their containers.
  3. Media queries that apply different styles at different screen sizes.

Modern CSS adds Flexbox, Grid, clamp() and container queries, which often make layouts responsive with fewer media queries. It differs from adaptive design, which serves a few fixed layouts for specific device sizes.

Q2. Why is the viewport meta tag needed?#

HTML
<meta name="viewport" content="width=device-width, initial-scale=1" />

Answer: without it, mobile browsers assume the page was designed for desktop, render it at about 980px wide and zoom out, so text looks tiny and media queries don't trigger as expected. width=device-width sets the layout viewport to the device's width in CSS pixels. Avoid user-scalable=no or maximum-scale=1: blocking zoom is an accessibility failure.

Q3. What is mobile-first design? Why is it preferred?#

CSS
/* Mobile-first: base styles for small screens */
.products { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* Then enhance for larger screens with min-width */
@media (min-width: 640px)  { .products { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .products { grid-template-columns: repeat(4, 1fr); } }

/* Desktop-first would start wide and use max-width to undo styles */

Answer: mobile-first writes base CSS for the smallest screen and adds complexity with min-width queries. Benefits: phones download and apply less override CSS, it forces you to prioritise essential content, and progressive enhancement is easier than stripping features away. Desktop-first uses max-width queries and often leads to more overrides.

Media queries and units#

Q4. How do you choose breakpoints? What else can media queries check?#

Answer: set breakpoints where your content breaks (lines get too long, cards get too cramped), not for specific devices, which change every year. Common starting points are around 640px, 768px, 1024px and 1280px. Media queries can also test user preferences and input type:

CSS
@media (prefers-color-scheme: dark)   { :root { --bg: #111; --text: #eee; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (hover: hover) and (pointer: fine) { .card:hover { transform: translateY(-2px); } }
@media (orientation: landscape) { .gallery { grid-auto-flow: column; } }
@media print { nav, .ads { display: none; } }

Q5. What is the difference between px, em and rem?#

UnitRelative toBest for
pxFixed CSS pixelBorders, small details, shadows
emThe element's own font size (parent's for font-size)Padding that scales with a component's text, like buttons
remThe root (html) font sizeFont sizes, spacing, layout widths
%Parent's sizeFluid widths
CSS
html { font-size: 100%; }      /* respect the user's browser setting (usually 16px) */
h1 { font-size: 2rem; }        /* 32px by default, scales if the user increases font size */
.btn { font-size: 1rem; padding: 0.5em 1em; }  /* padding grows with the button text */

Why it matters: rem respects the user's browser font-size preference, which is important for accessibility. em compounds in nested elements (1.2em inside 1.2em is 1.44 times the base), which surprises people.

Q6. What are viewport units, and what problem do dvh and svh solve?#

Answer: vw and vh are 1% of the viewport width and height. On mobile, 100vh is based on the largest viewport (address bar hidden), so a full-screen hero gets cut off when the bar is visible. Newer units fix this:

  • svh: small viewport height (browser UI visible).
  • lvh: large viewport height (browser UI hidden).
  • dvh: dynamic, updates as the UI shows and hides.
CSS
.hero { min-height: 100vh; min-height: 100dvh; }  /* fallback first */

Also, 100vw includes the vertical scrollbar width on desktop, so width: 100vw can cause horizontal scrolling. Prefer width: 100%.

Q7. How does clamp() create fluid typography and spacing?#

CSS
h1 {
  /* min 1.75rem, preferred grows with viewport, max 3rem */
  font-size: clamp(1.75rem, 1.2rem + 2.5vw, 3rem);
}
.section { padding-block: clamp(2rem, 5vw, 6rem); }
.container { width: min(100% - 2rem, 1200px); margin-inline: auto; }

Answer: clamp(min, preferred, max) picks the preferred value but never goes below the minimum or above the maximum. Text grows smoothly between screen sizes instead of jumping at breakpoints. Mixing rem into the preferred value keeps it responsive to user zoom; using vw alone can prevent text from scaling when users zoom. min() and max() are useful for containers.

Media and components#

Q8. How do you make images responsive?#

CSS
img, video { max-width: 100%; height: auto; display: block; }
.thumb { aspect-ratio: 16 / 9; object-fit: cover; width: 100%; }
HTML
<!-- Resolution switching: same image, different sizes -->
<img
  src="product-800.webp"
  srcset="product-400.webp 400w, product-800.webp 800w, product-1600.webp 1600w"
  sizes="(min-width: 1024px) 33vw, (min-width: 640px) 50vw, 100vw"
  alt="Blue running shoes, side view"
  width="800" height="600"
  loading="lazy" />

Answer: max-width: 100% stops images overflowing. srcset lists available widths and sizes tells the browser how wide the image will be displayed, so it downloads the smallest file that looks sharp on that screen and pixel density. Always set width and height (or aspect-ratio) to reserve space and avoid layout shift, and lazy-load images below the fold.

Q9. When do you use the picture element?#

HTML
<picture>
  <!-- Art direction: a tighter crop on phones -->
  <source media="(max-width: 600px)" srcset="hero-mobile.avif" type="image/avif" />
  <!-- Format fallback -->
  <source srcset="hero.avif" type="image/avif" />
  <source srcset="hero.webp" type="image/webp" />
  <img src="hero.jpg" alt="Team working at a long desk" width="1600" height="900" />
</picture>

Answer: use <picture> for art direction (a different crop or image at different sizes) and for serving modern formats like AVIF and WebP with a fallback. For the same image at different resolutions, srcset on <img> is enough. The <img> inside is required and carries the alt text.

Q10. What are container queries, and how do they differ from media queries?#

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

.card { display: grid; gap: 12px; }

@container card (min-width: 420px) {
  .card { grid-template-columns: 160px 1fr; }  /* image beside text when there's room */
}

Answer: media queries respond to the viewport; container queries respond to the size of a parent container. A card can then adapt whether it's in a narrow sidebar or a wide main column on the same page, making components truly reusable. Container query units (cqi, cqw) size things relative to the container.

Usability and testing#

Q11. What touch and usability considerations matter on mobile?#

  • Touch targets at least 44 to 48 CSS pixels with spacing between them (WCAG 2.2 sets a 24px minimum).
  • Readable text of at least 16px for body copy; this also stops iOS zooming into focused inputs.
  • Don't rely on hover; touch screens have no hover state, so menus and tooltips need tap alternatives.
  • Correct input types (type="email", inputmode="numeric", autocomplete) show the right keyboard.
  • Avoid horizontal scrolling; wrap wide tables in a scroll container with overflow-x: auto.
  • Safe areas on notched phones: padding: env(safe-area-inset-bottom).

Q12. How do you test a responsive website?#

Answer:

  • Browser DevTools device mode to check breakpoints, touch emulation and DPR. Drag the width continuously rather than only checking preset devices.
  • Real devices, at least one iOS and one Android phone, because emulators miss browser UI, keyboard and performance behaviour.
  • Zoom to 200% and 400% (WCAG reflow) to make sure content doesn't overlap or require two-dimensional scrolling.
  • Lighthouse on mobile settings for performance and tap-target issues.
  • Visual regression tests (Playwright screenshots at several widths) to catch layout breaks in CI.

Quick revision#

NeedSolution
Mobile renders correctly<meta name="viewport" content="width=device-width, initial-scale=1">
Enhance for larger screensMobile-first + min-width queries
Accessible font sizesrem
Full-height mobile section100dvh with 100vh fallback
Fluid typeclamp(min, preferred, max)
Right image sizesrcset + sizes
Different crop or format<picture>
Component adapts to its slotContainer queries

Related: Flexbox and Grid interview questions and Core Web Vitals interview questions.

Key takeaways#

  • Always include the viewport meta tag and never disable zoom.
  • Build mobile-first with min-width breakpoints set where content breaks.
  • Use rem for type and spacing, clamp() for fluid sizing, and dvh for mobile full-height sections.
  • Serve responsive images with srcset, sizes and <picture>, and reserve space with width and height.
  • Use container queries for reusable components and test on real devices and at high zoom.