Implementing Mobile-First Media Queries

Start by writing your base styles for the smallest screen. Then use @media (min-width: …) queries to enhance the layout at larger breakpoints. This ensures performance and usability on mobile devices.

/* Base mobile styles */
.container {
  padding: 1rem;
}

/* Tablet and up */
@media (min-width: 768px) {
  .container {
    max-width: 720px;
    margin: 0 auto;
  }
}

/* Desktop and up */
@media (min-width: 1024px) {
  .container {
    max-width: 960px;
  }
}

Key Points

  • Use mobile-first: write base styles for small screens, then scale up.
  • Choose logical breakpoints based on content, not device names.
  • Prefer fluid units (%, rem, vw/vh) for widths and typography.
  • Test responsiveness by resizing the browser and using device emulators.