Sikau

CSS · Day 13 · about 30 min

Media queries

Mobile first, then bigger screens.

One page, every screen

Most people browse on phones. responsive design means one page that looks right on a phone, a tablet and a big monitor. Media queries apply CSS only when the screen matches a condition.

Mobile first

  • Mobile first: write the simple, one-column phone layout as the default, then add @media (min-width: …) rules for wider screens.
  • Choose breakpoints where *your* layout starts to look wrong, not for specific devices.
  • The page also needs <meta name="viewport" content="width=device-width, initial-scale=1"> in its head.
  • Other useful queries: (prefers-color-scheme: dark), (prefers-reduced-motion: reduce), (hover: hover).

The rest of this lesson

  • Why mobile first worksexplain
  • Beyond screen widthexplain
  • When does it apply?predict
  • Which rule wins?predict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 19 lessons of CSS