Code of the Day
IntermediateResponsive Design

Mobile-First Design

Mobile-first means writing base styles for the smallest screen and adding complexity for larger screens — a discipline that produces leaner, more maintainable CSS.

Web FoundationsIntermediate7 min read
Recommended first
By the end of this lesson you will be able to:
  • Explain the mobile-first principle and why it produces leaner CSS
  • Contrast mobile-first with desktop-first and identify when each is appropriate
  • Apply a practical mobile-first workflow to a multi-column layout
  • Recognise the common mistake of claiming mobile-first while writing desktop-first

"Mobile-first" is one of the most repeated phrases in responsive design — and one of the most frequently misunderstood. It is not just about making a site that works on phones. It is a discipline for writing CSS that starts with the simplest version of a layout and layers complexity upward.

The core principle

Write your base styles for the smallest screen. Then use min-width media queries to progressively enhance the layout for wider viewports.

/* Base: single column — works on every screen */
.page {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

/* Wide enough for a sidebar: add it */
@media (min-width: 768px) {
  .page {
    grid-template-columns: 200px 1fr;
  }
}

/* Wide enough for a three-column layout */
@media (min-width: 1100px) {
  .page {
    grid-template-columns: 200px 1fr 300px;
  }
}

The single-column grid is the base. Complexity accumulates in layers. A narrow viewport sees the simplest rules; a wide viewport sees all of them.

Why it produces leaner CSS

Mobile layouts are usually simpler: one column, no hover states, fewer decorative elements, tighter spacing. Writing for mobile first means your base CSS is naturally minimal. Media queries then add what is needed.

Desktop-first inverts this. Your base CSS is the complex, wide-screen layout. Media queries have to undo it for smaller screens: remove columns, flatten grids, shrink fonts, collapse navigation. You end up fighting against your own styles.

Compare what the max-width equivalent of the grid above looks like:

/* Base: three-column layout */
.page {
  display: grid;
  grid-template-columns: 200px 1fr 300px;
  gap: 1.5rem;
}

/* Strip the right column at medium widths */
@media (max-width: 1099px) {
  .page {
    grid-template-columns: 200px 1fr;
  }
}

/* Strip the sidebar too at small widths */
@media (max-width: 767px) {
  .page {
    grid-template-columns: 1fr;
  }
}

Both versions work. But the desktop-first version requires you to think through what to remove at each step. The mobile-first version only asks what to add. For layouts with many components, that cognitive difference accumulates quickly.

"Leaner" does not just mean fewer lines. It means styles that are easier to predict and debug. When every rule builds on a simpler base, tracking why a component looks wrong on a specific screen size is far less painful.

The practical workflow

A mobile-first workflow has a small number of steps:

  1. Sketch the mobile layout first. One column. No sidebars. Navigation collapsed into a menu. Content stacked vertically.

  2. Write CSS for that layout. No media queries yet. Make it look correct on a 375px-wide viewport.

  3. Resize the browser slowly. Watch for the moment the layout starts to look wrong — too much whitespace, line lengths too long, empty space that could hold a sidebar. That is your first .

  4. Add a min-width query at that point. Introduce the next level of layout complexity inside it.

  5. Repeat. Keep widening until the layout stops improving, then stop adding breakpoints.

Three or four breakpoints covers the range from phone to wide monitor for most designs. Resist the temptation to add a breakpoint for every device — content should drive the decision.

When desktop-first is appropriate

Mobile-first is the right default. There is one category of exception: software where mobile is a genuine edge case.

Internal admin dashboards, data-heavy analytics tools, code editors, and complex forms are built primarily for people sitting at a desk with a large screen. Forcing a complex interaction model into a one-column mobile layout adds significant effort for a use case that may represent 2% of your traffic.

In these cases, writing desktop-first is pragmatic. A "mobile view" can exist as a graceful degradation — readable and usable, not feature-complete.

The common mistake

Many codebases claim to be "mobile-first" but are actually desktop-first with a max-width: 600px block bolted on at the bottom of the stylesheet. The tell: if the base styles (outside any media query) describe a wide-screen layout with columns and sidebars, it is desktop-first — regardless of what the comments say.

A genuine mobile-first base looks sparse. It should feel like it is missing things. The media queries are where the richness lives.

If you ever open DevTools, shrink the viewport to 375px, and notice the base layout has a multi-column grid or a sticky sidebar, the codebase is desktop-first. Auditing this on a large project is tedious. Setting the discipline from the start is much cheaper.

Where to go next

You have the structural approach. Next: Fluid Typography and Spacing — using clamp() to scale type and space smoothly between viewport sizes instead of jumping at breakpoints.

Finished reading? Mark it complete to track your progress.

On this page