docs.rodeo

MDN Web Docs mirror

CSS media queries

{{CSSRef}} 

The CSS media queries module enables testing and querying of viewport values and browser or device features, to conditionally apply CSS styles based on the current user environment. Media queries are used in the CSS @media rule and other contexts and languages such as HTML and JavaScript.

Media queries are a key component of responsive design. They enable conditional setting of CSS styles depending on the presence or value of device characteristics. It’s common to use a media query based on {{Glossary("viewport")}}  size to set appropriate layouts on devices with different screen sizes — for example three columns on a wide screen or a single column on a narrow screen.

Other common examples include increasing the font size and hiding navigation menus when printing a page, adjusting the padding between paragraphs when a page is viewed in portrait or landscape mode, or increasing the size of buttons to provide a larger hit area on touchscreens.

In CSS, use the {{cssxref("@media")}}  at-rule to conditionally apply part of a style sheet based on the result of a media query. To conditionally apply an entire style sheet, use {{cssxref("@import")}} .

When designing reusable HTML components, you may also use container queries, which allow you to apply styles based on the size of a containing element rather than the viewport or other device characteristics.

Reference

At-rules

Descriptors

[!NOTE] CSS media queries level 5 introduces five @media descriptors that have not been implemented: {{cssxref("@media/environment-blending", "environment-blending")}} , {{cssxref("@media/horizontal-viewport-segments", "horizontal-viewport-segments")}} , {{cssxref("@media/nav-controls", "nav-controls")}} , {{cssxref("@media/vertical-viewport-segments", "vertical-viewport-segments")}} , and {{cssxref("@media/video-color-gamut", "video-color-gamut")}} 

[!NOTE] CSS media queries level 4 deprecated three @media descriptors: {{cssxref("@media/device-aspect-ratio", "device-aspect-ratio")}} , {{cssxref("@media/device-height", "device-height")}} , and {{cssxref("@media/device-width", "device-width")}} .

Data types and operators

Glossary terms

Guides

Specifications

{{Specifications}} 

See also

In this article

View on MDN