--- url: "https://web.dev/articles/media-query-range-syntax" titulek: "New syntax for range media queries | web.dev" h1: "New syntax for range media queries Stay organized with collections Save and categorize content based on your preferences." popis: "Find out how this new syntax can streamline media queries." jazyk: "en" kanonicka: "https://web.dev/articles/media-query-range-syntax" drobecky: [] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 23:12:39" znaku: 2837 slov: 450 kodovani: "iso-8859-2" sha256: "9da13c9e7b8f79dd6b269c84a07356ef4f5286f93df565f8ee53a3875ed7e68d" --- New syntax for range media queries Stay organized with collections Save and categorize content based on your preferences. Find out how this new syntax can streamline media queries. Rachel Andrew Media Queries enabled [responsive design](/learn/design), and the range features that enable testing the minimum and maximum size of the viewport are used [by around 80% of sites](https://almanac.httparchive.org/en/2021/css#media-features-in-use) that use media queries. The Media Queries Level 4 specification includes an improved syntax for these range queries. Browser Support 104 104 102 16.4 The following examples show how it can streamline your queries. A typical media query testing for a minimum viewport width, would be written as follows: `@media (min-width: 400px) { // Styles for viewports with a width of 400 pixels or greater. }` The new syntax allows for the use of a comparison operator: `@media (width >= 400px) { // Styles for viewports with a width of 400 pixels or greater. }` Testing for a maximum width: `@media (max-width: 30em) { // Styles for viewports with a width of 30em or less. }` And, the version using the level 4 syntax: `@media (width <= 30em) { // Styles for viewports with a width of 30em or less. }` This syntax has the potential to streamline queries, in particular when testing between two widths. In the following example, the media query tests for a viewport with a minimum width of 400px, and a maximum width of 600px. `@media (min-width: 400px) and (max-width: 600px) { // Styles for viewports between 400px and 600px. }` This can be rewritten in the new syntax as: `@media (400px <= width <= 600px ) { // Styles for viewports between 400px and 600px. }` The feature that you are testing, in this case `width`, goes between the two values. In addition to making media queries less verbose, the new syntax has the advantage of accuracy. The `min-` and `max-` queries are inclusive of the specified values, for example `min-width: 400px` tests for a width of 400px or greater. The new syntax lets you be more explicit about what you mean and avoid the potential of clashing queries. To use the new range syntax while accounting for browsers that have not yet implemented it, there is a [PostCSS plugin](https://github.com/postcss/postcss-media-minmax) that will rewrite the new syntax to the old in your stylesheets. Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2023-12-09 UTC.