Episode 1 — Fundamentals / 1.9 — CSS Responsive Design

1.9.a — Mobile-First Strategy

In one sentence: Mobile-first means writing your base CSS for the smallest screen, then layering on complexity with min-width media queries as the viewport grows — a form of progressive enhancement that produces leaner, faster, more maintainable stylesheets.

Navigation: ← 1.9 Overview · 1.9.b — Media Queries →


1. What "mobile-first" actually means

Mobile-first is a CSS authoring strategy, not a device obsession. Your base styles — the code outside any media query — target the narrowest viewport. Wider layouts are added in ascending min-width queries.

/* Base: mobile (no query) */
.card { padding: 1rem; }

/* Tablet and up */
@media (min-width: 768px) {
  .card { padding: 2rem; }
}

/* Desktop and up */
@media (min-width: 1024px) {
  .card { display: flex; gap: 2rem; }
}

The opposite — desktop-first — starts with the widest layout and overrides downward with max-width queries.


2. Mobile-first vs desktop-first

AspectMobile-first (min-width)Desktop-first (max-width)
Base stylesSmallest screenLargest screen
Queries addComplexity as viewport growsConstraints as viewport shrinks
Progressive enhancementNatural fit — base is simpleGraceful degradation — base is complex
CSS weightLighter on mobile (fewer overrides)Heavier on mobile (more overrides)
Mental model"What do I add at wider sizes?""What do I remove at smaller sizes?"

Interview tip: Most teams and frameworks (Bootstrap 5, Tailwind) default to mobile-first because it aligns with progressive enhancement and produces less CSS for the devices with the weakest hardware.


3. Progressive enhancement in practice

Progressive enhancement means every user gets a working experience; capable browsers get a richer one. Mobile-first CSS is progressive enhancement applied to layout:

┌──────────────────────────────────────────────┐
│  Base CSS (mobile)                           │
│  ┌────────────────────────────────────────┐  │
│  │  + min-width: 768px (tablet)           │  │
│  │  ┌──────────────────────────────────┐  │  │
│  │  │  + min-width: 1024px (desktop)   │  │  │
│  │  └──────────────────────────────────┘  │  │
│  └────────────────────────────────────────┘  │
└──────────────────────────────────────────────┘

Each layer adds — never subtracts. If a query fails to load, the user still has a functional mobile layout.


4. Content priority on mobile

Small screens force you to decide what matters most. This is a design advantage, not a limitation.

DecisionMobileTablet/Desktop
NavigationHamburger menu or bottom barFull horizontal nav
SidebarHidden or collapsed below main contentVisible alongside main
Grid columns1 column, stacked2–4 columns
ImagesSmaller, essential onlyLarger, decorative allowed
CTAsFull-width, thumb-friendlyInline, standard size

Rule of thumb: If content isn't important enough for the mobile view, question whether it belongs at all.


5. Touch targets

Mobile users tap with fingers, not cursors. Small tap targets cause frustration and mis-taps.

GuidelineMinimum size
WCAG 2.5.8 (AAA)44 × 44 CSS pixels
Google / Material48 × 48 CSS pixels
Apple HIG44 × 44 points (≈ 44px on 1x)
.btn {
  min-height: 48px;
  min-width: 48px;
  padding: 0.75rem 1.5rem;
}

/* Links in a list need spacing too */
.nav-list a {
  display: block;
  padding: 0.75rem 1rem;
}

Common mistake: The visible element looks big enough, but the clickable area (the element's actual box) is tiny. Always check the computed size in DevTools.


6. Performance benefits of mobile-first

BenefitWhy
Less CSS parsed on mobileBase styles are minimal; complex layout rules live inside queries phones never match
Fewer overridesAdding rules (min-width) is cheaper than undoing them (max-width)
Smaller initial paintSimpler DOM + fewer layout calculations = faster first paint on weak CPUs
Natural code splittingComplex grid/multi-column code only loads conceptually when needed

Phones have less CPU, less memory, and often slower networks. Sending them the simplest CSS by default is the right trade-off.


7. Writing mobile-first: step by step

  1. Reset / normalize — apply a consistent base.
  2. Typography first — set font-size, line-height, spacing at the body level.
  3. Single-column layout — stack everything vertically; let natural document flow do the work.
  4. Component styles — padding, colors, borders at mobile scale.
  5. First breakpoint (e.g., min-width: 640px) — introduce two-column layouts, larger spacing.
  6. Second breakpoint (e.g., min-width: 1024px) — full desktop layout, sidebars, wider containers.
  7. Polishmin-width: 1280px for wide screens if needed.
/* Step 2–4: base mobile */
body {
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  padding: 1rem;
}

.grid {
  display: grid;
  gap: 1rem;
}

/* Step 5: tablet */
@media (min-width: 640px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
}

/* Step 6: desktop */
@media (min-width: 1024px) {
  body { padding: 2rem 4rem; }
  .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
  }
}

8. Common anti-patterns

Anti-patternProblemFix
Desktop CSS with max-width overrides to "fix mobile"Bloated, fragile, hard to maintainRewrite mobile-first
display: none on half the page at mobileContent is still downloaded; screen readers may still see itRestructure content priority
Fixed pixel widths everywhereBreaks between breakpointsUse relative units (%, rem, fr)
Only testing at exact breakpoint widthsMisses the "in-between" viewportsDrag the browser edge slowly to find issues

9. Key takeaways

  1. Base CSS = mobile. Media queries add complexity for wider screens.
  2. min-width queries are the mobile-first tool; max-width is desktop-first.
  3. Touch targets: 48px minimum interactive area.
  4. Mobile-first produces less CSS, faster rendering, and better content hierarchy.
  5. If it's not worth showing on mobile, rethink whether it belongs anywhere.

Explain-It Challenge

Explain without notes:

  1. Why does mobile-first CSS download less unused code on phones than desktop-first CSS?
  2. A button looks 48px tall in the design mockup, but users complain about mis-taps. What might be wrong, and how do you diagnose it?
  3. Your teammate wrote all desktop styles first and wants to "just add max-width queries for mobile." What's your argument for rewriting mobile-first?

Navigation: ← 1.9 Overview · 1.9.b — Media Queries →