CSS media queries

Quick reference for CSS media queries: width conditions, range syntax, and prefers-reduced-motion, including why breakpoints are not device models.

A media query is a boolean condition over the viewport or device environment, not a label for a phone, tablet, or desktop. A rule such as (min-width: 48rem) or (width >= 48rem) asks whether the viewport width meets that threshold. It does not name an iPad or a specific phone. The CSS tutorial already introduces a 48rem two-column grid; this page is the query syntax and the accessibility conditions around it, not a rewrite of that lesson or the #responsive anchor.

prefers-reduced-motion is part of keeping a responsive layout usable. When the query matches reduce, cut or replace non-essential motion; do not hide the control or the content. The default (no reduce preference) still has to be usable without that query.

Examples are complete HTML and CSS fragments. They were parsed with PostCSS and a selector AST parser for syntax and structure. They were not rendered in a browser here, and this is not a visual or accessibility test.

Official sources: MDN and the CSS specification. Fragments were checked with PostCSS 8 for syntax and structure. That is not a CSS conformance suite, and this is not a browser render or visual test.

CSS reference catalog → · CSS tutorial overview →

Width conditions are not device models

@media groups a block of rules behind a media condition. The common typography is @media (min-width: 48rem) { … } or the Level 4 range form @media (width >= 48rem) { … }. Both are viewport-width tests. max-width, min-height, and orientation work the same way: they describe a measurement, not a product name.

A breakpoint is the threshold where your layout changes. Choose it from the design’s own need for space, and prefer relative units such as rem so the condition tracks the root font size. Publishing a table of “iPhone / iPad / desktop” pixel widths as if they were official CSS is misleading: devices change, and users zoom and resize windows.

Syntax or propertyInitial / defaultInheritedApplies toNotes
@media——stylesheet at-ruleA conditional group. The block applies only when its media query list matches. It is not a property, so it has no initial value or inheritance.
min-width / max-width———Media features that compare the viewport width to a length. (min-width: 48rem) is equivalent to the range form (width >= 48rem) in Media Queries Level 4 and 5.
width / height / orientation———Other common features. width and height are viewport dimensions. orientation is portrait or landscape, still a condition, not a device class.

A 48rem width query is a viewport condition

@media (min-width: 48rem) { .page { grid-template-columns: 1fr 1fr; } }
@media (width >= 48rem) { .page { grid-template-columns: 1fr 1fr; } }

Both queries test the viewport width against 48rem. Neither query names a tablet or a phone.

  • The tutorial uses the min-width form on a project grid. This example keeps that threshold so the two pages stay consistent, and adds the equivalent range syntax.
  • This is a parse of the condition, not a measured viewport or a device-lab result.
html
<main class="page">
  <article class="card">One</article>
  <article class="card">Two</article>
</main>
<style>
.page { display: grid; gap: 1rem; }
.card { border: 1px solid #0B5853; background: #F3EFE4; padding: 0.5rem; font-family: sans-serif; }
@media (min-width: 48rem) {
  .page { grid-template-columns: 1fr 1fr; }
}
@media (width >= 48rem) {
  .page { column-gap: 1.5rem; }
}
</style>

What this markup means

The default rule is a one-column grid. The min-width: 48rem block adds two columns only when the viewport is at least 48rem wide. The second block uses the equivalent range feature (width >= 48rem) to widen the gap; it is the same kind of width test, not a second device profile. Nothing in the stylesheet mentions a phone or tablet, because CSS has no official device-model media type for those names.

Related: CSS tutorial: responsive grid, Grid

MDN documentation → · CSS specification →

prefers-reduced-motion and a usable default

prefers-reduced-motion lets a user ask for less motion. The standard values are no-preference and reduce. When the query matches reduce, remove or replace decorative transitions and animations; keep the same control and the same content visible. Hiding a button, collapsing essential text, or making an action unreachable only inside that query is not a reduced-motion strategy.

The stylesheet without that query must already be usable. Media queries layer enhancements or alternatives; they are not the only place accessibility lives. This page records the syntax and that requirement. It does not run a user-preference or screen-reader test.

Syntax or propertyInitial / defaultNotes
prefers-reduced-motion—A media feature. no-preference is the default environment; reduce means the user has requested less motion.
prefers-color-scheme / hover / pointer—Related environment features. They are also conditions (light or dark, hover capability), not device model names. They are not expanded on this page.

Reduce motion without hiding the control

@media (prefers-reduced-motion: reduce) {
  .pulse, .pulse:hover { transition: none; transform: none; }
}

The reduce branch turns off a decorative scale transition. The button stays in the document and stays labeled.

  • The hover rule is a progressive enhancement. The Save label does not depend on hover or on the animation.
  • Pair this feature with the Transitions and Animations pages rather than treating motion as only a media-query topic.
html
<button class="pulse" type="button">Save</button>
<style>
.pulse { font-family: sans-serif; color: #0B5853; background: #F3EFE4; border: 1px solid #0B5853; transition: transform 0.25s ease; }
.pulse:hover { transform: scale(1.06); }
@media (prefers-reduced-motion: reduce) {
  .pulse, .pulse:hover { transition: none; transform: none; }
}
</style>

What this markup means

The default rule adds a short transform transition on hover. Inside prefers-reduced-motion: reduce, both the transition and the hover transform are set to none, so the motion does not run. The button element and its Save text remain. That is the intended pattern: keep the interface, drop the decoration. This fragment was parsed for structure; it was not used to read a real user preference or to test accessibility in a browser.

Related: Transitions, Animations, Transforms

MDN documentation → · CSS specification →