Skip to content

Behavior of "unknown " media feature name/value #35435

@mdubet

Description

@mdubet

Media Queries Level 3/4/5 have a consistent description of the way to handle unknown media feature name or unknown media feature value: transform the media query to not all.

An unknown or , or disallowed , results in the value "unknown". A whose value is "unknown" must be replaced with not all.

(quote from https://drafts.csswg.org/mediaqueries-5/#error-handling)

With the introduction of the new <general-enclosed> term in the grammar and the 3-valued logic evaluation, and the intention of allowing future-proof query matching in the case of unknown media feature, my understanting of the spec would be that:

  • when one (or several) media feature name or value is unknown, and the complete media query is unknown, such as (width: foobar) (unkown value) or (foobar) (unknown name), it should be replaced with not all.
  • when one (or several) media feature name or value is unknown, but the complete media query is either true or false, it should not be replaced such as (foobar: foobarvalue) or (color) (assuming color is true).

However, the WPT media queries tests rely on another behavior:

return match.media == query;

Even when the media query result is unknown, they don't expect it to be replaced by not all. Is this a bug ?

Current implementations

The implementations in Firefox and Chrome have different behaviors on this issue.

Firefox Developer Edition (v104):

> window.matchMedia("(scan: foobar)")
> MediaQueryList { media: "not all", matches: false, onchange: null }

> window.matchMedia("(foobar: none) or (color)")
> MediaQueryList { media: "not all", matches: false, onchange: null }

In Chrome Canary:

> window.matchMedia("(scan: foobar)")
> MediaQueryList {media: '(scan: foobar)', matches: false, onchange: null}

> window.matchMedia("(foobar: none) or (color)")
> MediaQueryList {media: '(foobar: none) or (color)', matches: true, onchange: null}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions