CSS mixins
- Category
- CSS
- Type
- New or changed feature
- Status
- Proposed (Chrome Proposed)
- Intent stage
- None
Summary
Defines a reusable, parameterized block of style declarations and nested style rules with the @mixin rule, then expands them in place within a style rule via @apply as if the mixin's contents had been written there directly. The mixin body puts the declarations and rules to emit inside an @result block, while any local custom properties used to compute them stay private and never reach the element; parameters can be typed and given defaults, and @result can contain conditional rules such as @supports and @media. This lets authors package consistent patterns – component styles, effects like gradient text, responsive shorthands – once and reuse them across a stylesheet without a CSS pre-processor.
Motivation
To reuse a consistent pattern across a stylesheet, whether component styles, effects like gradient text, or responsive shorthands, authors currently must either duplicate the same declarations and nested rules in every style rule that needs them, which drifts out of sync and is error prone, or reach for a CSS pre-processor such as Sass, which introduces a separate language and build step and cannot respond to the cascade at runtime. Custom properties share individual values but not whole blocks of declarations and rules and offer no way to parameterize a pattern or keep the local custom properties used to compute it private. The @mixin rule fills this gap natively, letting authors package such patterns once and expand them in place as if the contents had been written there directly.
Standards & signals
- Specification: https://drafts.csswg.org/css-mixins-1/#defining-mixins
- Firefox: No signal
- Safari: No signal
- Web developers: Positive — Long-standing, heavy use of the equivalent Sass/Less mixins.
- Tracking bug: https://issues.chromium.org/issues/406935599
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=css-mixins
- 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+CSS%20mixins
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=CSS%20mixins
- Baseline status: https://webstatus.dev/?q=CSS%20mixins
Explainers: https://css.oddbird.net/sasslike/mixins-functions