D DevBrainBox

CSS Mobile First

CSS

What is Mobile First in CSS?

Mobile First means you start designing for small screens (like phones) and then gradually add styles for larger screens (like tablets and desktops) using media queries.

Why Mobile First?

  • Most users browse on mobile devices.
  • Small screens have more layout limitations, so it’s smart to start from there.
  • Easier to scale up than to scale down.

How It Works

  1. Write base CSS for mobile devices (small screens).
  2. Use media queries with min-width to add styles for larger screens.
/* Base styles (mobile first) */
body {
  font-size: 14px;
  padding: 10px;
}

.container {
  width: 100%;
}

/* Tablet styles (screen width 768px and up) */
@media (min-width: 768px) {
  body {
    font-size: 16px;
  }

  .container {
    width: 80%;
  }
}

/* Desktop styles (screen width 1024px and up) */
@media (min-width: 1024px) {
  .container {
    width: 70%;
    margin: 0 auto;
  }
}

This setup:

  • Starts with mobile-friendly styles
  • Enhances the layout as screen size increases
PrincipleDescription
Start smallWrite basic layout for mobile users
Use min-widthAdd bigger-screen styles progressively
Keep it responsiveCombine with %, vw, and rem units

Benefits of Mobile First

  • Faster loading on mobile
  • Better accessibility
  • Easier to maintain and scale
  • More future-proof

On this page