Favorites

@mixin CSS At-Rule

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

The @mixin at-rule defines a reusable block of declarations that is inserted into other rules with @apply. It is experimental and not yet supported in browsers.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The @mixin at-rule defines a reusable block of styles that can be inserted into other style rules with the companion @apply at-rule. While a custom function created with @function returns a single value, a mixin returns whole declarations and even nested rules, which makes it similar to the mixins found in preprocessors such as Sass. It is defined in the CSS Functions and Mixins specification.

A mixin's name starts with two dashes, for example --visually-hidden or --button-variant(). Like a custom function, it can take parameters, each with an optional type and default value, and these are read inside the body with var(). When a rule contains @apply --button-variant(#2563eb);, the declarations and nested rules from the mixin are substituted at that point, using the arguments given. A mixin can also accept a block of content from the place where it is applied, which is inserted wherever the mixin uses @contents.

Mixins help keep stylesheets consistent by putting repeated patterns, such as focus rings, truncated text or color variants of a component, in one place, without needing a build step. Because they are expanded by the browser, they can use custom properties and respond to the element's context, which preprocessor mixins cannot.

@mixin and @apply are experimental and not yet supported in any browser without a flag. The syntax may still change before it ships.

Syntax

@mixin <mixin-name>( <mixin-parameter>#? ) {
  <declaration-rule-list>
}

/* used with */
@apply <mixin-name>( <arguments>? );

Values

  • <mixin-name>The name of the mixin, starting with two dashes, for example --truncate(. Parentheses are used even when there are no parameters.
  • <mixin-parameter>Optional, comma-separated. Each parameter is a custom property name, optionally followed by a type and a default value after a colon.
  • @applyInserts a mixin's declarations into the current rule, for example @apply --truncate();. Arguments are passed in the parentheses.
  • @contentsUsed inside a mixin to mark where a block of styles passed to @apply should be inserted.

Example

@mixin --truncate() {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

@mixin --button-variant(--color : #2563eb) {
background: var(--color);
border: 1px solid color-mix(in oklab, var(--color), black 20%);
&:hover {
background: color-mix(in oklab, var(--color), white 15%);
}
}

.title {
@apply --truncate();
}

.danger {
@apply --button-variant(#dc2626);
}

Browser Support

The following information will show you the current browser support for the CSS at-rule @mixin. 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

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.