CSSMobile-First vs Desktop-First

Mobile-First vs Desktop-First Approach

Mobile-first design means starting with styles for mobile devices, then progressively enhancing for larger screens using min-width media queries. Desktop-first does the opposite using max-width. Mobile-first is the modern best practice—it prioritizes mobile users and results in simpler, more maintainable code.

Mobile-First Approach

CSS
/* Base styles (mobile) - no media query needed */
body {
  font-size: 14px;
  line-height: 1.4;
}

.container {
  width: 100%;
  padding: 12px;
  max-width: 100%;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* Enhance for tablet and larger */
@media (min-width: 768px) {
  body {
    font-size: 16px;
    line-height: 1.6;
  }

  .container {
    max-width: 750px;
    padding: 20px;
    margin: 0 auto;
  }

  .grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Further enhance for desktop */
@media (min-width: 1024px) {
  body {
    font-size: 16px;
  }

  .container {
    max-width: 1000px;
    padding: 30px;
  }

  .grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}
Desktop-First Approach (not recommended)

CSS
/* Base styles assume large desktop screen */
body {
  font-size: 18px;
}

.container {
  width: 1200px;
  margin: 0 auto;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

/* Then reduce for smaller screens */
@media (max-width: 1024px) {
  .container {
    width: 900px;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  body {
    font-size: 16px;
  }

  .container {
    width: auto;
    padding: 12px;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}
Mobile-First Best Practices

Principle

Mobile-First

How It Works

Base CSS

Mobile optimized

Minimal styles for small screens

Progression

@media (min-width: ...)

Add enhancements for larger

Performance

Better

Less CSS for mobile users

Fallback

Works everywhere

Graceful degradation built-in

CSS
/* Navigation: mobile-first */
.nav-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #ddd;
}

.nav-menu.open {
  display: block;
}

.hamburger {
  display: block;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
}

/* Tablet and up: full navigation */
@media (min-width: 768px) {
  .nav-menu {
    display: flex;
    position: static;
    border: none;
    gap: 20px;
  }

  .hamburger {
    display: none;
  }
}

/* Sidebar layout: mobile-first */
.layout {
  display: flex;
  flex-direction: column;
}

.sidebar {
  order: 2;
  width: 100%;
}

.content {
  order: 1;
  width: 100%;
}

/* Tablet and up: sidebar beside content */
@media (min-width: 768px) {
  .layout {
    flex-direction: row;
  }

  .sidebar {
    order: 1;
    flex: 0 0 250px;
    width: 250px;
  }

  .content {
    order: 2;
    flex: 1;
  }
}

/* Grid: mobile-first responsiveness */
.gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1000px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Typography: mobile-first scaling */
h1 {
  font-size: 24px;
  line-height: 1.2;
}

@media (min-width: 768px) {
  h1 {
    font-size: 32px;
  }
}

@media (min-width: 1024px) {
  h1 {
    font-size: 40px;
  }
}
When mobile-first works best

CSS
/* Web apps and progressive web apps (PWA) */
/* Heavy mobile usage */
/* Performance critical */
/* Need offline support */

/* Responsive design from the start */
/* Not just making desktop site work on mobile */
/* True mobile experience */

/* Content-first design */
/* Focus on essential content */
/* Eliminate unnecessary desktop elements */

/* Performance-sensitive projects */
/* Mobile users on slower connections */
/* Reduce unused CSS */
/* Smaller initial CSS payload */
Tools and utilities for mobile-first

CSS
/* Breakpoint variables for consistency */
:root {
  --breakpoint-sm: 640px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1280px;
}

@media (min-width: var(--breakpoint-md)) {
  /* tablet and up */
}

/* Tailwind CSS: mobile-first by default */
/* <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3"> */
/* Defaults to 1 column */
/* 2 columns at md breakpoint */
/* 3 columns at lg breakpoint */

/* Framework defaults */
/* Bootstrap: mobile-first approach */
/* Tailwind: mobile-first by design */
/* Foundation: supports both approaches */
Note
Mobile-first means writing CSS for mobile devices first, then progressively enhancing for larger screens using `min-width` media queries. Benefits: simpler code, better performance, works on all devices, easier maintenance. Start with essential mobile styles, enhance with `@media (min-width: 768px)` for tablets, and further enhance for desktops. This is the modern best practice for responsive design.
Next
Viewport meta tag: [Viewport Meta Tag](/css/viewport-meta).