@custom-media
- Category
- CSS
- Type
- New or changed feature
- Status
- Proposed (Chrome Proposed)
- Intent stage
- None
Summary
The proposed @custom-media at-rule is a feature that would allow developers to define and name their own media queries. This would make responsive design code cleaner and more maintainable by reducing repetition. For example: @custom-media --narrow-window (max-width: 30em); @media (--narrow-window) { /* styles for narrow windows */ }
Motivation
The primary motivation for introducing the @custom-media feature is to enhance CSS development by making it more efficient, readable, and maintainable. It directly addresses the common issue of developers having to repeatedly write the same media query conditions, allowing them instead to define meaningful, reusable aliases. This feature is a feature highly requested by developers; the Chromium bug report has 233 stars, Chris Coyier and Stefan Judis have shared interest in this feature in their posts: https://www.stefanjudis.com/notes/can-we-have-custom-media-queries-please/, https://css-tricks.com/can-we-have-custom-media-queries-please/.
Standards & signals
- Specification: https://www.w3.org/TR/mediaqueries-5/#custom-mq
- Firefox: No signal
- Safari: Closed Without a Position
- Web developers: Positive — 233 stars on bug report, few posts from web authors: https://www.stefanjudis.com/notes/can-we-have-custom-media-queries-please/ https://css-tricks.com/can-we-have-custom-media-queries-please/
- Tracking bug: https://issues.chromium.org/issues/40781325
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=custom-media
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+%40custom-media
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=%40custom-media
- Baseline status: https://webstatus.dev/?q=%40custom-media