Native CSS Mixins in Chromium: How @mixin, @apply, @contents, and HTML-Free Theming WorkArticle · digest for December 2
Overhead studio still life: native CSS mixin stencils laid over a base page grid, changing the theme without touching the HTML.
Article4 sections≈ 9 min

Native CSS Mixins in Chromium: How @mixin, @apply, @contents, and HTML-Free Theming Work

Imagine restyling and rearranging an entire website from a single stylesheet without handing clients control over your HTML. Or defining screen widths once and writing @apply --mobile { ... } instead of copy-pasting long media queries across dozens of files. The browser itself can now do all of this without Sass or PostCSS—though for now, only in recent Chromium builds behind an experimental flag.

The Microsoft Edge team is building this implementation in Chromium based on the November 4, 2026 CSS Custom Functions and Mixins Module Level 1 draft, edited by Miriam Suzanne and Tab Atkins-Bittner. Part one of that spec (@function custom functions) already shipped in stable Chrome 139. Part two, native mixins, is still a draft, yet you can already run live code today.

How @mixin Differs from Variables and @function

The distinction between CSS reuse tools is straightforward. A regular CSS variable (--accent) is a single paint can: it holds one value or token. A native @function works like a mixer: it takes arguments, computes something, and still returns a single value via result for a single property. @mixin, on the other hand, is a complete stencil with all layers intact. It returns an entire block of declarations: properties, nested selectors like &:hover, pseudo-elements, @media, @supports, and @container.

You declare a mixin with @mixin and apply it with @apply. Names always start with --, just like custom properties. Here is the classic accessibility helper that hides an element visually while keeping it readable for screen readers:

/* Reusable block for screen-reader-only content */
@mixin --visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Inject the block into a target selector */
.skip-link {
  @apply --visually-hidden;
}

The browser applies those declarations as if you had written them straight inside .skip-link. No build step required—everything runs inside the style engine.

Mixins also accept typed parameters with defaults, and support nested rules and functions like color-mix() inside their body:

/* Typed <color> parameters with default values */
@mixin --button(
  --bg <color>: royalblue,
  --fg <color>: white
) {
  background: var(--bg);
  color: var(--fg);
  padding: 0.5em 1em;
  &:hover {
    background: color-mix(in oklch, var(--bg), black 20%);
  }
}

.primary { @apply --button; }
.danger  { @apply --button(crimson); }
.custom  { @apply --button(palegreen, black); }

Pass an argument of the wrong type and it falls back to the default. Pass more arguments than declared parameters and @apply simply does nothing without breaking neighboring styles. Under the hood, mixin names are tree-scoped: when names collide, higher @layer priorities win, and within the same layer, the later declaration wins.

Conditional Mixins and @contents: Named Breakpoints and Dark Mode

Anyone who has built responsive layouts in plain CSS knows the pain of scattering thresholds like 40rem and 64rem across an entire codebase. One breakpoint tweak from design turns into a find-and-replace hunt.

Inside @mixin, @media, @supports, and @container all work, and the @contents directive acts as a slot with an open window. You write the condition once, then pass your styles inside @apply --name { ... }—the browser drops them right where @contents sits. The slot even supports fallback styles like @contents { background: white; } when called without braces. Passing an empty block @apply --card {} counts as an explicit opt-out and skips the fallback.

Plain CSS finally gets clean named breakpoints:

/* Single source of truth for responsive breakpoints */
@mixin --mobile  { @media (width < 40rem)          { @contents; } }
@mixin --tablet  { @media (40rem <= width < 64rem) { @contents; } }
@mixin --desktop { @media (width >= 64rem)         { @contents; } }

/* Use readable names inside components */
.sidebar {
  @apply --mobile  { display: none; }
  @apply --tablet  { inline-size: 12rem; }
  @apply --desktop { inline-size: 20rem; }
}

Width thresholds now live in one place, and component styles read far more clearly. A dark-mode wrapper via prefers-color-scheme takes just a few lines too:

@mixin --if-dark-mode {
  @media (prefers-color-scheme: dark) {
    @contents;
  }
}

.header {
  background: white;
  color: black;
  /* Applies only in dark mode */
  @apply --if-dark-mode {
    background: black;
    color: white;
  }
}

On the surface this looks like Sass, yet the mechanics differ completely. A preprocessor expands mixins into static CSS at build time, inflating your bundle. A native @mixin lives in the browser's live cascade, reacts to dynamic CSS variables, and works seamlessly with @container.

Private Variables with @private and the Mixin Zen Garden Experiment

Mixins often need temporary variables for internal math without leaking them onto the target element. In the November spec and Chromium, that is handled by @private (early drafts tested @result, but current syntax uses direct declarations in the mixin body plus @private for hidden variables):

Paper collage of Mixin Zen Garden: one unchanged HTML sheet and a fan of six swappable themes with a sealed pocket for private variables.

@mixin --gradient-text(--from: tomato, --to: gold) {
  /* Local variable stays hidden from the outside */
  @private {
    --angle: 90deg;
  }
  background: linear-gradient(
    var(--angle),
    var(--from),
    var(--to)
  );
  background-clip: text;
  color: transparent;
}

The element using --gradient-text gets gradient text, yet --angle never appears in its computed styles.

Mixins shine even brighter in white-label theming, where you own the platform and clients want to skin it for their brand. Previously, you had two extremes. You could hand clients full CSS over your markup—like the famous 2003 CSS Zen Garden, where different stylesheets transformed one HTML page beyond recognition. The catch is that HTML immediately becomes a public API: clients couple to your tags and nesting, and any markup refactor breaks their themes. The other extreme is exposing only CSS variables. That's safe, yet cramped: clients can tweak colors and spacing, but adding a new grid, pseudo-element, or animation forces you to invent new tokens.

Theming approachHTML controlWhat clients can changeMain problem
Full CSS over HTMLLost (markup = API)Everything: layout, animations, pseudo-elementsAny HTML refactor breaks themes
CSS variables (var())Full controlOnly pre-exposed valuesToo rigid for custom designs
Native @mixinFull control (with validation)Any properties, @media, animationsRequires checking nested selectors

Mixins offer a middle ground. The platform places calls to undeclared mixins across logical UI zones in its base CSS. Without a client theme, they do nothing and the default look renders. A theme file then defines whichever @mixin blocks it wants with any properties, media queries, or animations:

/* Base platform CSS: theme entry points */
body      { @apply --page; }
header    { @apply --masthead; }
header h1 { @apply --site-title; }

/* Client theme defines the mixins it wants */
@mixin --page {
  font: 1.2rem/1.6 Georgia, serif;
  background: lightyellow;
}
@mixin --masthead {
  background: darkblue;
  color: white;
}
@mixin --site-title {
  font-size: 2rem;
  font-weight: bold;
}

Microsoft engineer Patrick Brosset tested this pattern in his Mixin Zen Garden demo (source on GitHub). One static HTML page switches across six completely different themes built purely with mixins: Midnight, Paper, Brutalist, Newspaper, Sunset, and Terminal. Three simple rules emerged: a theme doesn't have to define every mixin, one mixin per logical region is plenty, and naming them by role (--sidebar-heading) rather than tag or color lets you refactor HTML freely without breaking anyone's design.

Where to Try It, Caveats, and Shadow DOM Prospects

It is still too early to ship @mixin to production. The Editor's Draft explicitly warns that mixins are much less stable than @function, and syntax details may still shift.

How to enable it and current browser support

You can test the examples and open Mixin Zen Garden in recent Chromium builds (Chrome, Edge): open about://flags and enable Experimental Web Platform features. Implementation progress is tracked in WPT tests. Firefox has an open standards discussion (mozilla/standards-positions#1459) without an implementation yet; Safari and WebKit have no support.

White-label theming also has an architectural loophole. Nothing stops a client from writing a nested selector inside your mixin, like @mixin --masthead { & h2 { ... } }, and reaching back into your markup. That turns HTML into a public contract again. In real production platforms, you'll still need a CSS validator to strip disallowed selectors inside client mixins.

Once the standard reaches all browser engines, though, its usefulness will go far beyond theming. Document-level mixins could eventually pierce Shadow DOM boundaries—isolated web-component subtrees that normal page selectors can't reach—giving teams a clean way to style component internals from the outside. And design-system teams will get a single native layer for accessibility and progressive enhancement, letting developers pull in vetted blocks like --visually-hidden so baseline team policies hold uniformly across an entire app.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 4