media query

A CSS rule, written @media, that applies styles only when a condition about the device or user settings is true.

In more detail

Conditions include screen width, prefers-color-scheme, prefers-contrast, forced-colors and prefers-reduced-motion. JavaScript can check the same conditions with window.matchMedia and listen for changes.

Example

In the browser: @media (min-width: 800px) targets wide viewports, and preference queries such as prefers-color-scheme and prefers-reduced-motion follow user settings. Media queries only know the viewport, not where a component sits.

Related terms

Taught in

References