Sass meta.content-exists()

Intermediate
8 min read
Updated: Nov 2026
5 examples
Dart Sass

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

SCSS
@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.

content-exists vs accepts-content

Two related helpers, different questions:

HelperAsksWhere
meta.content-exists()Did this include pass a content block?Only inside a mixin
meta.accepts-content($mixin)Can this mixin value take @content?Anywhere you have a mixin value
Empty @include m {}Still counts as content passedcontent-exists → true
Bare @include m;No content blockcontent-exists → false
Safe defaults.

Use @if meta.content-exists() to emit fallback CSS when callers omit a content block.

SCSS Examples

Examples use @use "sass:meta". Open View Compiled CSS for verified output (matches official Sass docs behavior).

Example 1 — Official Idea (No Content Block)

A bare include reports false.

SCSS
@use "sass:meta";

@mixin debug-content-exists {
  --passed: #{meta.content-exists()};
  @content;
}

.no-block {
  @include debug-content-exists;
}

How It Works

  1. Include has no curly-brace block.
  2. content-exists is false.
  3. @content emits nothing.
  4. Matches the official docs “false” case.

Example 2 — Official Idea (With Content Block)

Passing a content block reports true.

SCSS
@use "sass:meta";

@mixin debug-content-exists {
  --passed: #{meta.content-exists()};
  @content;
}

.with-block {
  @include debug-content-exists {
    color: green;
  }
}

How It Works

  1. Caller passes a content block.
  2. content-exists is true.
  3. @content inserts color: green.
  4. Matches the official docs “true” case.

Example 3 — Empty Content Block Still Counts

@include m {} passes a block even when it is empty.

SCSS
@use "sass:meta";

@mixin check {
  --passed: #{meta.content-exists()};
  @content;
}

.empty {
  @include check {}
}

How It Works

  1. Empty braces still form a content block.
  2. Result is true.
  3. No CSS comes from the empty @content.
  4. Do not treat “empty” as “missing.”

Example 4 — Safe Default When Content Is Missing

Branch on content-exists for fallback styles.

SCSS
@use "sass:meta";

@mixin optional {
  @if meta.content-exists() {
    .inner {
      @content;
    }
  } @else {
    outline: 1px dashed gray;
  }
}

.a {
  @include optional;
}

.b {
  @include optional {
    color: blue;
  }
}

How It Works

  1. No block → fallback outline.
  2. With block → wrap content in .inner.
  3. Compile-time branch only.
  4. Useful for optional slots in layout mixins.

Example 5 — Contrast with meta.accepts-content

Capability of the mixin vs whether this include passed content.

SCSS
@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;
  }
}

How It Works

  1. --can stays true for both includes.
  2. --passed depends on the caller.
  3. accepts-content is about the mixin definition.
  4. 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.

vs

Wrong helper for capability

Before meta.apply, use meta.accepts-content.

global

Prefer the module form

Global content-exists() still exists; new projects should use meta.content-exists.

Sass Support

Prefer the module form with current Dart Sass.

APIStatus
meta.content-exists()Dart Sass via @use "sass:meta"
Global content-exists()Legacy; prefer module form
WhereInside a mixin only
Return typeBoolean

Compile with the Dart Sass CLI.

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().

Compile Notes

Practical checklist:

checklist.txt
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

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.

Next: Sass meta.feature-exists()

Check whether the compiler supports a named Sass feature (deprecated helper).

meta.feature-exists() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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