Skip to main content

media-feature-range-notation

Specify context or prefix notation for media feature ranges.

@media (width >= 600px) and (min-width: 600px) {}
/** ↑ ↑
* These media feature notations */

Use this rule to enforce a convention. A range media feature can be written with a min- or max- prefix, or in the context notation with a comparison operator.

Choose:

  • "context" to write ranges as comparisons, including the exclusive ones that prefixes can't express
  • "prefix" for older browsers, which don't support the context notation

The fix option can automatically fix some of the problems reported by this rule.

This rule supports 1 message argument: the configured notation.

Options​

"context"​

Media feature ranges must always use context notation.

{
"media-feature-range-notation": "context"
}

The following patterns are considered problems:

@media (min-width: 1px) {}
@media (min-width: 1px) and (max-width: 2px) {}

The following patterns are not considered problems:

@media (width >= 1px) {}
@media (1px <= width <= 2px) {}

"prefix"​

Media feature ranges must always use prefix notation.

{
"media-feature-range-notation": "prefix"
}

The following patterns are considered problems:

@media (width >= 1px) {}
@media (1px <= width <= 2px) {}

The following patterns are not considered problems:

@media (min-width: 1px) {}
@media (min-width: 1px) and (max-width: 2px) {}

Optional secondary options​

except​

{ "except": ["array", "of", "options"] }

"exact-value"​

Reverse the primary option for media features with exact values.

Given:

{
"media-feature-range-notation": ["context", { "except": ["exact-value"] }]
}

The following pattern is considered a problem:

@media (min-width: 1px) {}

The following pattern is not considered a problem:

@media (width: 1px) {}