Skip to the page
css reference · responsive basics

CSS @media queries

type
at-rule
applies to
a block of other rules, conditionally
inherits
n/a
common values
(max-width: 600px), (min-width: 900px)

Where it goes

Anywhere in a stylesheet. The rules inside only take effect when the condition matches. Specificity and order still apply inside it.

Example

.row {
  flex-direction: row;
}

@media (max-width: 600px) {
  .row {
    flex-direction: column;
  }
}

Common mistakes

  • Writing one rule for "mobile" and never testing the sizes between phone and desktop. A tablet can fall between two rules that do not account for it.
  • Designing for desktop first and adding max-width queries on top. Starting from the phone and adding min-width queries is usually less CSS to undo.

Related

Updated 24 October 2026. Practice it in the css route, or read more on MDN.