Home Sass Meta meta.accepts-content() Sass meta.accepts-content() Definition
Definition and Usage meta.accepts-content($mixin) returns a boolean : whether the given mixin value can accept a @content block. Official docs: it returns true if accepting content is possible , even when the mixin does not always use @content. Load it with @use "sass:meta" on Dart Sass 1.69+ .
Higher-order mixins. Use this before meta.apply() when a helper sometimes forwards @content and sometimes does not.
Not the same as content-exists. accepts-content asks “can this mixin take content?” meta.content-exists() asks “did the current include pass content?”
Syntax
Syntax @use "sass:meta";
meta.accepts-content($mixin); //=> boolean
@mixin plain($n) { width: $n; }
@mixin wrap { @content; }
meta.accepts-content(meta.get-mixin("plain")); // false
meta.accepts-content(meta.get-mixin("wrap")); // true
// Module API — prefer meta.accepts-content after @use "sass:meta" Pattern: get a mixin value → check accepts-content → branch before meta.apply with or without a content block.
Code
SCSS Examples Examples target Dart Sass 1.69+ with @use "sass:meta". Open View Compiled CSS for verified output.
1. Basic 2. With @content 3. Conditional 4. Guard apply 5. vs content-exists Example 1 — Mixin Without @content A plain mixin returns false.
@use "sass:meta";
@mixin box($padding) {
padding: $padding;
}
.basic {
--accepts: #{meta.accepts-content(meta.get-mixin("box"))};
} .basic {
--accepts: false;
} How It Works box has no @content.get-mixin returns a mixin value.accepts-content is false.Do not forward a content block into it.Example 2 — Mixin With @content A wrapper that includes @content returns true.
@use "sass:meta";
@mixin media($query) {
@media #{$query} {
@content;
}
}
.true-case {
--accepts: #{meta.accepts-content(meta.get-mixin("media"))};
} .true-case {
--accepts: true;
} How It Works media declares @content.Accepting content is possible.Result is true.Safe to forward a content block via meta.apply.Example 3 — Conditional @content Still Counts Official idea: true if content is possible, even when not always used.
@use "sass:meta";
@mixin maybe($flag) {
@if $flag {
@content;
}
}
.conditional {
--accepts: #{meta.accepts-content(meta.get-mixin("maybe"))};
} .conditional {
--accepts: true;
} How It Works @content sits behind @if.Capability still exists.Returns true.Not a guarantee that content always runs.Example 4 — Guard meta.apply Forward a content block only when the target mixin accepts one.
@use "sass:meta";
@mixin plain {
color: blue;
}
@mixin with-content {
.inner {
@content;
}
}
@mixin apply-if-content($mixin) {
@if meta.accepts-content($mixin) {
@include meta.apply($mixin) {
outline: 1px solid red;
}
} @else {
@include meta.apply($mixin);
}
}
.a {
@include apply-if-content(meta.get-mixin("plain"));
}
.b {
@include apply-if-content(meta.get-mixin("with-content"));
} .a {
color: blue;
}
.b .inner {
outline: 1px solid red;
} How It Works Check accepts-content first.plain gets apply without content.with-content receives the outline block.Avoids forwarding content into mixins that cannot take it.Example 5 — Contrast with meta.content-exists Capability vs whether content was passed on this include.
@use "sass:meta";
@mixin wrap {
--can: #{meta.accepts-content(meta.get-mixin("wrap"))};
--passed: #{meta.content-exists()};
@content;
}
.no-block {
@include wrap;
}
.with-block {
@include wrap {
color: green;
}
} .no-block {
--can: true;
--passed: false;
}
.with-block {
--can: true;
--passed: true;
color: green;
} How It Works --can stays true for both includes.--passed depends on the caller.accepts-content is about the mixin definition.content-exists is about this include call. Edge Cases & Pitfalls Most mistakes are passing a string name or confusing capability with “content was passed.”
type Pass a mixin value Use meta.get-mixin("name"). A bare string is not a mixin value.
true true ≠ always uses contentConditional @content still reports true. Capability is not a runtime guarantee.
version Needs Dart Sass 1.69+ Older compilers and LibSass / Ruby Sass do not provide this API.
Toolchain
Sass Support Prefer the module form with Dart Sass 1.69+.
API Status meta.accepts-content()Dart Sass 1.69+ via @use "sass:meta" Argument Mixin value (e.g. from meta.get-mixin) Return type Boolean LibSass / Ruby Sass Not available
Compile with the Dart Sass CLI .
Remember
Key Takeaways Boolean capability check for mixin @content.
Pass a mixin value from get-mixin / module maps.
Guard meta.apply before forwarding content.
Dart Sass 1.69+ via @use "sass:meta".
One line: when you need to know if a mixin value can take @content before applying it, call meta.accepts-content($mixin).
Practice
Compile Notes Practical checklist:
1. @use "sass:meta"
2. Get a mixin value (meta.get-mixin / module-mixins)
3. Call meta.accepts-content($mixin)
4. Branch before meta.apply with or without @content
5. Use content-exists() inside mixins for "was content passed?" Frequently Asked Questions What does Sass meta.accepts-content() do? meta.accepts-content($mixin) returns true or false for whether a mixin value can accept a @content block. Official docs: it returns true if accepting content is possible, even when the mixin does not always use @content.
What do I pass as $mixin? A mixin value—usually from meta.get-mixin("name"), or from meta.module-mixins. Do not pass a plain string name.
When is this useful? When you write higher-order helpers that @include meta.apply($mixin) and sometimes forward @content. Check accepts-content first so you only pass a content block to mixins that support it.
Does true mean the mixin always uses @content? No. true means it is possible for the mixin to accept content. The mixin might use @content only on some code paths.
How does this relate to meta.apply? meta.apply can forward a @content block into the applied mixin. meta.accepts-content tells you whether that is safe/possible for a given mixin value.
Which compilers support meta.accepts-content? Dart Sass 1.69+. LibSass and Ruby Sass do not provide this helper. Prefer current Dart Sass.
Next: Sass meta.apply() Include a mixin value and optionally forward @content.
meta.apply() → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion