Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Media Queries #421

Closed
3 tasks
ramiy opened this issue Sep 14, 2023 · 8 comments
Closed
3 tasks

Custom Media Queries #421

ramiy opened this issue Sep 14, 2023 · 8 comments
Labels
focus-area-proposal Focus Area Proposal

Comments

@ramiy
Copy link
Contributor

ramiy commented Sep 14, 2023

Description

The Media Queries Level 5 specification defines “Custom Media Queries” as named aliases for longer and more complex media queries. With custom media queries developers define them once and use them in multiple places, simplifying the process of updating the media query to a single line of code.

Example:

@custom-media --desktop (max-width: 70em);
@custom-media --mobile (max-width: 40em);

@media screen and (--desktop) {
  /* styles */
}
@media screen and (--mobile) {
  /* styles */
}
@media print and (--desktop) {
  /* styles */
}
@media print and (--mobile) {
  /* styles */
}

Furthermore, with the help of JS CSS.customMedia.set(), developers will be able to change breakpoints dynamically.

Specification

https://www.w3.org/TR/mediaqueries-5/#custom-mq

Open Issues

No response

Tests

No response

Current Implementations

  • Blink
  • Gecko
  • WebKit

Standards Positions

No response

Browser bug reports

https://bugs.chromium.org/p/chromium/issues/detail?id=1234172

Developer discussions

https://open-props.style/#media-queries

Polls & Surveys

No response

Existing Usage

No response

Workarounds

this can be emulated using style queries (#433):

@media (width <= 40em) {
  :root { --screen: mobile; }
}
@media (width <= 70em) {
  :root { --screen: desktop; }
}

@container style(--screen: mobile) {
  /* styles */
}

@container style(--screen: desktop) {
  /* styles */
}

Accessibility Impact

No accessibility impact.

Privacy Impact

No privacy impact.

@ramiy ramiy added the focus-area-proposal Focus Area Proposal label Sep 14, 2023
@frehner
Copy link

frehner commented Sep 15, 2023

@mayank99
Copy link

this can be emulated using style queries (#433):

@media (width <= 40em) {
  :root { --screen: mobile; }
}
@media (width <= 70em) {
  :root { --screen: desktop; }
}

@container style(--screen: mobile) {
  /* styles */
}

@container style(--screen: desktop) {
  /* styles */
}

@gsnedders

This comment was marked as resolved.

@lukewarlow lukewarlow mentioned this issue Sep 17, 2023
3 tasks
@foolip

This comment was marked as resolved.

@jensimmons
Copy link
Contributor

Do you intend for this to include the script-based version of this? There is not spec for that yet. This proposal could be for the declarative version only, as your examples show. Correct?

@foolip
Copy link
Member

foolip commented Oct 18, 2023

Are there any tests for the declarative feature here in WPT already?

@foolip
Copy link
Member

foolip commented Oct 18, 2023

To answer my own questions, I did a search for "custom-media" in WPT and didn't find anything, so I guess there are no tests yet.

@wpt-interop
Copy link

Thank you for proposing Custom Media Queries for inclusion in Interop 2024.

We wanted to let you know that this proposal was not selected to be part of Interop this year.

As of the deadline, the specifications for Custom Media Queries were not yet complete enough to allow interoperable implementations. To make progress on this area in the future, it will first be necessary to ensure that the feature has a clear specification in a standards track document.

For an overview of our process, see proposal selection. Thank you again for contributing to Interop 2024!

Posted on behalf of the Interop team.

@bkardell

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus-area-proposal Focus Area Proposal
Projects
Status: Done
Development

No branches or pull requests

8 participants