meta.content-exists() belongs to the built-in sass:meta module. It tells you whether the current mixin was given a @content block. This page covers safe defaults, vs meta.accepts-content, the “inside a mixin only” rule, and five compiled examples.
01
Concept
Was @content passed?
02
Module
@use "sass:meta"
03
Returns
true / false
04
Scope
Inside mixins only
05
vs accepts
Passed vs can accept
06
Practice
5 examples
Concept
What Is meta.content-exists()?
Mixins can optionally receive a block of styles with @content:
Official docs: meta.content-exists() returns whether the current mixin was passed a @content block. Use that boolean in @if to change padding, wrappers, or fallback styles when callers omit the block.
💡
Beginner tip
Think of a gift bag: content-exists asks “did someone put something in the bag on this call?” It does not ask “can this bag hold gifts?”—that is meta.accepts-content.
Foundation
📝 Syntax
styles.scss
@use "sass:meta";
// Recommended — no parameters
meta.content-exists()
// Legacy global name
content-exists()
Parameters
None. The function inspects the mixin that is currently running.
Return value
Type
Result
Boolean
true if a @content block was passed; otherwise false
Errors
Official docs: throws an error if called outside of a mixin. Keep it inside @mixin … { … }.
content-exists answers “was a block passed?”, not “does the block contain CSS?” Empty braces still yield true.
Applications
🚀 Real-World Use Cases
Optional layout chrome — padding, wrappers, or gaps only when content exists.
Fallback copy styles — default color/weight when callers skip the block.
Debug / theme flags — set custom properties like --has-content for tooling.
Component APIs — one mixin that works as a shell or as a filled component.
Safer @content — branch before nesting content into deep selectors.
🧠 How Compilation Works
1
Include the mixin
Caller uses bare @include or passes a { … } block.
Source
2
Ask content-exists
Inside the mixin, Sass answers true or false for this include.
Compile
3
Branch and @content
@if picks styles; @content inserts the caller block when present.
Expand
4
✓
CSS ships
Browsers never see meta.content-exists—only finished rules.
Watch Out
⚠️ Common Pitfalls
Calling outside a mixin — official docs: this throws an error.
Confusing with accepts-content — that checks capability on a mixin value, not this include.
Empty braces surprise — @include m { } still counts as content passed.
Forgetting @content — detecting content is useless if you never insert it.
Expecting runtime checks — everything resolves when Sass compiles.
Pro Tips
💡 Best Practices
✅ Do
Use @use "sass:meta" and meta.content-exists()
Call it only inside @mixin
Pair with @if for optional chrome / fallbacks
Document whether your mixin expects content
Prefer Dart Sass for modern modules
❌ Don’t
Call it at the root of a stylesheet
Assume empty { } means false
Mix it up with meta.accepts-content
Expect the browser to evaluate it
Skip @content when you intend to forward styles
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about meta.content-exists()
Detect whether this mixin include received a @content block.
5
Core concepts
📝01
API
content-exists()
Call
📦02
Module
sass:meta
@use
✅03
Returns
boolean
Result
🔒04
Scope
mixin only
Safe
✓05
vs accepts
passed vs can
Compare
❓ Frequently Asked Questions
meta.content-exists() returns true or false for whether the current mixin was passed a @content block when it was included.
Only inside a mixin. Official docs: calling it outside a mixin throws an error.
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.
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.
Yes. content-exists() is the legacy global name. Prefer meta.content-exists after @use "sass:meta".
No. It runs at compile time. Browsers only see the CSS your mixin emits after the @if branches resolve.
Did you know?
Official Sass docs demonstrate meta.content-exists() with @debug inside a mixin: bare @include prints false, and an include with a content block prints true—the same boolean your @if branches use.
meta.content-exists() returns whether the mixin you are inside received a @content block. Use it for optional wrappers and fallbacks, call it only inside mixins, and reach for meta.accepts-content when you need to inspect a mixin value ahead of time.