Home Sass Meta meta.content-exists() Sass meta.content-exists() Definition
Definition and Usage meta.content-exists() returns a boolean : whether the current mixin was passed a @content block when it was included. Load it with @use "sass:meta".
Official sample idea. Inside a mixin, @debug meta.content-exists() prints false for a bare @include, and true when the include has a { ... } content block.
Mixin-only. Official docs: calling content-exists() outside a mixin throws an error. Keep it inside mixin bodies.
vs accepts-content. content-exists asks “did this include pass content?” meta.accepts-content asks “can this mixin value take content?”
Syntax
Syntax @use "sass:meta";
meta.content-exists(); //=> boolean (only inside a mixin)
@mixin debug-content-exists {
@debug meta.content-exists();
@content;
}
@include debug-content-exists; // false
@include debug-content-exists { // true
// Content!
}
// Global alias (legacy): content-exists()
// Prefer meta.content-exists after @use "sass:meta" Pattern: inside a mixin → check content-exists → branch defaults vs @content.
Code
SCSS Examples Examples use @use "sass:meta". Open View Compiled CSS for verified output (matches official Sass docs behavior).
1. Basic 2. With content 3. Empty block 4. Safe default 5. vs accepts-content Example 1 — Official Idea (No Content Block) A bare include reports false.
@use "sass:meta";
@mixin debug-content-exists {
--passed: #{meta.content-exists()};
@content;
}
.no-block {
@include debug-content-exists;
} .no-block {
--passed: false;
} How It Works Include has no curly-brace block.content-exists is false.@content emits nothing.Matches the official docs “false” case.Example 2 — Official Idea (With Content Block) Passing a content block reports true.
@use "sass:meta";
@mixin debug-content-exists {
--passed: #{meta.content-exists()};
@content;
}
.with-block {
@include debug-content-exists {
color: green;
}
} .with-block {
--passed: true;
color: green;
} How It Works Caller passes a content block.content-exists is true.@content inserts color: green.Matches the official docs “true” case.Example 3 — Empty Content Block Still Counts @include m {} passes a block even when it is empty.
@use "sass:meta";
@mixin check {
--passed: #{meta.content-exists()};
@content;
}
.empty {
@include check {}
} .empty {
--passed: true;
} How It Works Empty braces still form a content block.Result is true.No CSS comes from the empty @content.Do not treat “empty” as “missing.”Example 4 — Safe Default When Content Is Missing Branch on content-exists for fallback styles.
@use "sass:meta";
@mixin optional {
@if meta.content-exists() {
.inner {
@content;
}
} @else {
outline: 1px dashed gray;
}
}
.a {
@include optional;
}
.b {
@include optional {
color: blue;
}
} .a {
outline: 1px dashed gray;
}
.b .inner {
color: blue;
} How It Works No block → fallback outline.With block → wrap content in .inner.Compile-time branch only.Useful for optional slots in layout mixins.Example 5 — Contrast with meta.accepts-content Capability of the mixin vs whether this include passed content.
@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 content-exists bugs are calling it outside a mixin or confusing it with accepts-content.
scope Only inside mixins Outside a mixin, Sass throws. Do not call it at the root of a stylesheet or inside a plain function.
empty Empty braces still count @include m {} is true. Missing braces is false.
global Prefer the module form Global content-exists() still exists; new projects should use meta.content-exists.
Toolchain
Sass Support Prefer the module form with current Dart Sass.
API Status meta.content-exists()Dart Sass via @use "sass:meta" Global content-exists() Legacy; prefer module form Where Inside a mixin only Return type Boolean
Compile with the Dart Sass CLI .
Remember
Key Takeaways Boolean: did this include pass @content?
Call only inside mixins or Sass errors.
Empty braces still count as content passed.
Different from accepts-content (capability vs this call).
One line: when a mixin needs to know if the caller passed @content, call meta.content-exists().
Practice
Compile Notes Practical checklist:
1. @use "sass:meta"
2. Call only inside a mixin
3. Branch on meta.content-exists()
4. Remember empty {} still counts as true
5. Use accepts-content for mixin-value capability Frequently Asked Questions What does Sass meta.content-exists() do? meta.content-exists() returns true or false for whether the current mixin was passed a @content block when it was included.
Where can I call it? Only inside a mixin. Official docs: calling it outside a mixin throws an error.
How is it different from meta.accepts-content? content-exists answers “did this include pass @content?” for the mixin running now. accepts-content answers “can this mixin value take @content?” before you apply it.
Does an empty content block count? Yes. If the caller writes @include my-mixin { }, a content block was still passed, so content-exists() is typically true even when the block is empty.
Is there a global content-exists()? Yes. content-exists() is the legacy global name. Prefer meta.content-exists after @use "sass:meta".
Does this affect browsers? No. It runs at compile time. Browsers only see the CSS your mixin emits after the @if branches resolve.
Next: Sass meta.feature-exists() Check whether the compiler supports a named Sass feature (deprecated helper).
meta.feature-exists() → 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