Plain CSS does not support variables in media queries (yet)

Posted . Visible to the public.

It's not possible to use variables in media queries with plain CSS.

@media (max-width: var(--some-pixel-size)) { ... } /* Does not work */

Postcss Plugin

If you're using PostCSS to postprocess your CSS, you can configure postcss-custom-media and add this feature:

@custom-media --small-variable-name(max-width: 968px);

@media (--small-variable-name) { ... } /* works */
Profile picture of Niklas Hä.
Niklas Hä.
Last edit
Niklas Hä.
License
Source code in this card is licensed under the MIT License.
Posted by Niklas Hä. to makandra dev (2025-11-26 17:10)