Favorites

@custom-media CSS At-Rule

Experimental: This feature is not yet supported in any browser.
@custom-media
CSS At-RuleThis at-rule is not supported by modern browsers.
Updated 21st November 2026

The @custom-media at-rule gives a name to a media query, such as --tablet, so the same breakpoint can be reused. It is not yet supported in browsers.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The @custom-media at-rule defines a named alias for a media query, so the same breakpoint or condition can be reused across a stylesheet. Instead of repeating a query such as (width >= 768px) in many places, you define it once, for example @custom-media --tablet (width >= 768px);, and then refer to it by name in a media query: @media (--tablet) { ... }. Changing the definition updates every rule that uses it.

The name must start with two dashes, like a custom property. The value can be any media query list, including combinations with and, or and not, or the keywords true and false, which make the alias always or never match. Custom media queries can also refer to other custom media queries, which makes it possible to build a small, readable vocabulary of conditions such as --motion-ok, --dark or --touch.

Unlike custom properties, custom media queries are evaluated when the stylesheet is processed, not per element, so they cannot be changed for one part of the page or from JavaScript. If the same name is defined more than once, the last definition wins.

@custom-media is defined in Media Queries Level 5 but is not yet supported in any browser without a flag. Today, it is most commonly used through build tools such as PostCSS, which replace each alias with its full query before the CSS reaches the browser.

Syntax

@custom-media <extension-name> [ <media-query-list> | true | false ];

Values

  • <extension-name>The name of the custom media query, starting with two dashes, for example --tablet. It is used inside parentheses in media queries: @media (--tablet).
  • <media-query-list>The media query the name stands for, for example (width >= 768px) or screen and (prefers-color-scheme: dark).
  • true | falseMakes the custom media query always match (true) or never match (false). Useful for switching groups of rules on or off.

Example

@custom-media --tablet (width >= 768px);
@custom-media --desktop (width >= 1200px);
@custom-media --motion-ok (prefers-reduced-motion: no-preference);

@media (--tablet) {
.layout { grid-template-columns: 1fr 2fr; }
}

@media (--desktop) and (--motion-ok) {
.hero { animation: float 6s ease-in-out infinite; }
}

Browser Support

The following information will show you the current browser support for the CSS at-rule @custom-media. Hover over a browser icon to see the version that first introduced support for this CSS at-rule.

This at-rule is not supported by modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee