← All notes

CSS media queries: styles that respond to viewport and preference

Answer: The @media at-rule starts a media query. Designers use queries to react to form factor, including width and aspect ratio. Viewport size is a particularly useful feature. Preference queries can read accessibility settings and theme colors.

Starting a query

A media query is initiated with @media, a CSS at-rule, and covers many use cases.

Form factor includes width, aspect ratio, and other aspects. Media queries let designers respond.

When the goal is a responsive design, viewport dimensions are a useful media feature.

Combined queries apply their styles only if every condition is true. In this example, the viewport must be at least 50em wide and 30em tall.

Access to user preferences goes beyond height and width, covering accessibility features and theme colors.

Responsive pages and the viewport tag

Responsive web design is a strategy that adapts layout to the device in use, and it accounts for users' needs plus device capabilities.

A phone might get one column, a tablet two, and a desktop three or four.

When a page is optimized for many devices, a meta viewport tag belongs in the document head.

Without it, the page can load zoomed out and hard to read.

The initial-scale=1 value asks browsers for a 1:1 mapping of CSS pixels to device-independent pixels in any orientation.

Users are used to scrolling websites vertically but not horizontally. Size content to the viewport.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: web.dev, Media queries; web.dev, Responsive web design basics. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: web.dev, Media queries; web.dev, Responsive web design basics. CC-BY-4.0 (https://web.dev/learn/css/flexbox). Copyright Google LLC. web.dev text is CC BY 4.0.

Cite this

Permanent ID: iil:note:ssqbr7pz

iinventedlight. 2026. "CSS media queries: styles that respond to viewport and preference." iinventedlight Library, iil:note:ssqbr7pz, version of 2026-11-23. https://iinventedlight.com/library/notes/css-media-queries/. License: CC-BY-4.0.

@misc{iil_note_ssqbr7pz,
  author = {{iinventedlight}},
  title = {{CSS media queries: styles that respond to viewport and preference}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/css-media-queries/},
  note = {Permanent ID iil:note:ssqbr7pz. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/css-media-queries.md.