Media queries
Definition
Media queries apply CSS rules only when certain properties of the output or user settings match.
Media queries check, for example, the width of the display area, the media type, or the preference for reduced motion. If the conditions are met, the associated styles apply. They are a building block for flexible interfaces and can also influence print representations.
Simply explained
The page checks the available space and selects appropriate rules for its layout and presentation.
Why it matters in practice
This allows websites to respond to different display areas and preferences without providing a separate page for each device.
Example from business
Possible example: A website arranges cards vertically on narrow views and displays them side by side when there is sufficient width.
Limits and pitfalls
- The viewport width is not necessarily the device width. Many special cases complicate maintenance; real content and zoom must also be considered.
Origin & history
Media queries are part of CSS and extend conditional style selection beyond individual media types.
Use in mid-sized companies
- Businesses can define mobile views, print outputs, and reduced animations for their website and test them in the browser.
Frequently asked questions
Can media queries consider preferences?
Yes. Suitable queries detect, for example, the setting for reduced motion and allow adapted styles.
Sources
- Using media queries. · MDN (2026): Using media queries.
Editorially reviewed on: