Sass Booleans

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

Definition and Usage

Booleans are the logical values true and false. They come from literals, equality and relational operators, and many built-in functions.

Combine with words.

Use and, or, and not—not &&, ||, or !.

Drive styles with @if.

When a condition is truthy, Sass emits that block at compile time. Browsers never see the boolean logic.

Only false and null are falsey.

Empty strings, empty lists, and 0 are all truthy in Sass—unlike JavaScript.

Syntax

SCSS
$circle: true;

@if $circle {
  border-radius: 50%;
}

// Operators (words, not && / || / !)
true and false   // false
true or false    // true
not false        // true

// Comparisons return booleans
1px == 1px       // true
10px < 3px       // false

Pattern: get a boolean → combine with and / or / not → branch with @if (or pass as a mixin flag).

Common Patterns

Where booleans show up:

PatternResult idea
true / falseBoolean literals
== != < >Comparisons that return booleans
and / or / notBoolean operators (see boolean operators)
@if $cond { ... }Emit styles when truthy
false / nullThe only falsey values

SCSS Examples

Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).

Example 1 — Official Comparisons Return Booleans

Equality, relational ops, and math.compatible() produce true / false.

SCSS
@use "sass:math";

.demo {
  --eq-false: #{1px == 2px};
  --eq-true: #{1px == 1px};
  --lt-false: #{10px < 3px};
  --compat: #{math.compatible(100px, 3in)};
}

How It Works

  1. == / < evaluate at compile time.
  2. Results are boolean values.
  3. math.compatible also returns a boolean.
  4. Matches the official comparisons sample idea.

Example 2 — Official and / or / not

Word operators combine or invert booleans.

SCSS
.demo {
  --and-t: #{true and true};
  --and-f: #{true and false};
  --or-t: #{true or false};
  --or-f: #{false or false};
  --not-t: #{not true};
  --not-f: #{not false};
}

How It Works

  1. and needs both sides true.
  2. or needs either side true.
  3. not flips a single value.
  4. Details on boolean operators.

Example 3 — Official @if Mixin Flag

Pass a boolean into a mixin to optionally emit styles.

SCSS
@use "sass:math";

@mixin avatar($size, $circle: false) {
  width: $size;
  height: $size;

  @if $circle {
    border-radius: math.div($size, 2);
  }
}

.square-av {
  @include avatar(100px, $circle: false);
}
.circle-av {
  @include avatar(100px, $circle: true);
}

How It Works

  1. $circle: false skips border-radius.
  2. $circle: true emits the radius.
  3. math.div computes half the size.
  4. Matches the official Sass docs sample.

Example 4 — Truthiness and Falsiness

Only false and null fail conditions; 0, "", and () pass.

SCSS
@mixin check($name, $cond) {
  .#{$name} {
    @if $cond {
      content: "truthy";
    } @else {
      content: "falsey";
    }
  }
}

@include check(false-lit, false);
@include check(null-lit, null);
@include check(zero, 0);
@include check(empty-str, "");
@include check(empty-list, ());

How It Works

  1. false / null are falsey.
  2. 0 is truthy (unlike JS).
  3. "" and () are also truthy.
  4. More on null.

Example 5 — string.index as a Condition

Functions that return null or a number work directly in @if.

SCSS
@use "sass:string";

@mixin check($name, $cond) {
  .#{$name} {
    @if $cond {
      content: "truthy";
    } @else {
      content: "falsey";
    }
  }
}

@include check(space, string.index("hello world", " "));
@include check(missing, string.index("hello", " "));

How It Works

  1. Found → returns a number (truthy).
  2. Missing → returns null (falsey).
  3. No extra != null check required.
  4. Details on string.index().

Edge Cases & Pitfalls

Most boolean bugs come from JS-style operators or JS-style falsiness.

&&

No && / || / !

Write and, or, and not. See boolean operators.

0

0 is truthy

Do not treat zero like JavaScript. Compare explicitly if you need “is zero”.

""

Empty string / list are truthy

Check length or equality when emptiness matters.

@if

Compile-time only

@if never runs in the browser. Output is plain CSS.

Sass Support

Booleans and boolean operators are core Sass on Dart Sass.

FeatureStatus
true / falseSupported
and / or / notSupported
@if / @elseSupported
Truthy / falsey rulesOnly false and null are falsey

Compile with the Dart Sass CLI.

Key Takeaways

  • true / false are the boolean values.
  • and / or / not combine them (word operators).
  • @if emits styles when the condition is truthy.
  • Only false and null are falsey.

One line: use booleans (and truthy checks) with @if to choose what CSS Sass emits.

Compile Notes

Practical checklist:

checklist.txt
1. Use true / false literals or comparison results
2. Combine with and / or / not (not && / || / !)
3. Branch styles with @if / @else
4. Remember only false and null are falsey
5. Pass boolean flags into mixins for optional CSS

Frequently Asked Questions

Booleans are the logical values true and false. They come from literals, equality/relational operators, and many built-in functions such as map.has-key().
Use word operators: and (both true), or (either true), and not (opposite). Unlike JavaScript, Sass does not use &&, ||, or !.
Only false and null. Empty strings, empty lists, and the number 0 are all truthy.
Use @if $flag { … } to include a block when the condition is truthy.
No. Boolean logic and @if run at compile time. Browsers only see the CSS that was emitted.
string.index returns null when a substring is missing (falsey) and a number when found (truthy), so it works directly in @if conditions.

Next: Sass null

Learn the other falsey value and how missing results use null.

null →

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