Sass Equality Operators

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

Definition and Usage

Equality operators return whether two values are the same. Write == for equal and != for not equal. They run at compile time (often inside @if).

Official sample idea.

96px == 1in is true (compatible units); "Helvetica" == Helvetica is true (same contents).

Same type + same value.

What “same value” means depends on the type—numbers convert units, strings ignore quote state, lists care about separators and brackets.

Unitless ≠ length.

In modern Dart Sass, 1 != 1px. Older LibSass-style unitless equality is gone.

Syntax

SCSS
$a == $b   // true if equal
$a != $b   // true if not equal

1px == 1px;              // true
1 != 1px;                // true (unitless vs px)
96px == 1in;             // true (convertible units)

"Helvetica" == Helvetica; // true
null != false;            // true

// Typical use:
@if $theme == "dark" { ... }

Pattern: compare two values → get a boolean → branch with @if or combine with boolean operators.

By Type

How equality works for common types:

TypeEqual when…
NumbersSame value and units, or equal after unit conversion
StringsSame contents (quoted vs unquoted does not matter)
ListsSame items and same separator / bracket state
MapsSame keys and values
true / false / nullOnly equal to themselves

SCSS Examples

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

Example 1 — Official Number Samples

Same units, different units, unitless vs px, and conversion.

SCSS
@use "sass:meta";

.probe {
  --a: #{meta.inspect(1px == 1px)};
  --b: #{meta.inspect(1px != 1em)};
  --c: #{meta.inspect(1 != 1px)};
  --d: #{meta.inspect(96px == 1in)};
}

How It Works

  1. 1px == 1px same value and unit.
  2. 1px != 1em incompatible units.
  3. 1 != 1px unitless is not a length.
  4. 96px == 1in converts and matches.

Example 2 — Quoted vs Unquoted Strings

Quote state does not break content equality.

SCSS
@use "sass:meta";

.strings {
  --a: #{meta.inspect("Helvetica" == Helvetica)};
  --b: #{meta.inspect("Helvetica" != "Arial")};
}

How It Works

  1. Same letters → equal.
  2. Quotes are not part of the comparison.
  3. Different names → not equal.
  4. Matches the official string samples.

Example 3 — List Separators & Brackets

Same items can still be unequal if the list form differs.

SCSS
@use "sass:meta";

.lists {
  --a: #{meta.inspect((5px 7px 10px) == (5px 7px 10px))};
  --b: #{meta.inspect((5px 7px 10px) != (5px, 7px, 10px))};
  --c: #{meta.inspect((5px 7px 10px) != [5px 7px 10px])};
}

How It Works

  1. Identical space lists are equal.
  2. Comma vs space is a different list.
  3. Brackets change equality too.
  4. Matches the official list samples.

Example 4 — null Is Not false

true, false, and null only equal themselves.

SCSS
@use "sass:meta";

.bools {
  --a: #{meta.inspect(true == true)};
  --b: #{meta.inspect(true != false)};
  --c: #{meta.inspect(null != false)};
}

How It Works

  1. true == true holds.
  2. true != false holds.
  3. null != false — both are falsey, but not equal.
  4. Use == when you need the exact value, not just truthiness.

Example 5 — Branch with @if

Compare a theme token and emit different CSS.

SCSS
$theme: "dark";

.card {
  @if $theme == "dark" {
    color: #eee;
  } @else {
    color: #111;
  }
}

How It Works

  1. == returns a boolean at compile time.
  2. @if keeps only the matching branch.
  3. Browsers never see the comparison.
  4. Common for theme and config flags.

Edge Cases & Pitfalls

Most equality bugs are units, list form, or confusing equality with truthiness.

units

Unitless numbers ≠ lengths

1 != 1px in Dart Sass. Prefer consistent units or convert explicitly.

lists

Separators and brackets count

Space vs comma and bracketed vs unbracketed change equality even with the same items.

null

null is not false

Both are falsey in boolean context, but null == false is false.

compile-time

Resolved while compiling

The CSS output never contains ==—only the chosen values or branches.

Sass Support

Equality is core SassScript on Dart Sass.

OperatorMeaning
==True when both sides are equal
!=True when both sides are not equal
Unitless equalityDart Sass: unitless ≠ unit-bearing (LibSass differed)
Return typeBoolean (true / false)

Compile with the Dart Sass CLI.

Key Takeaways

  • == and != compare values at compile time.
  • Numbers convert units when compatible (96px == 1in).
  • Strings ignore quotes; lists care about form.
  • null != false even though both are falsey.

One line: use == / != to compare Sass values—watch units, list form, and null vs false.

Compile Notes

Practical checklist:

checklist.txt
1. Compare with == or !=
2. Keep number units consistent (or convertible)
3. Remember quoted == unquoted for same text
4. Check list separator / brackets
5. Use @if $x == $y for compile-time branches

Frequently Asked Questions

Sass provides == (equal) and != (not equal). They return true or false at compile time by comparing two values.
When they have the same value and the same units, or when their values match after converting between compatible units. Example: 96px == 1in is true. Unitless 1 is not equal to 1px in modern Dart Sass.
Yes, if the contents match. Official docs: "Helvetica" == Helvetica is true.
Yes. Space-separated lists are not equal to comma-separated lists, and bracketed lists are not equal to unbracketed lists, even with the same items.
No. Official docs: null != false is true. true, false, and null are only equal to themselves.
No. == and != are resolved when Sass compiles. The CSS file only keeps the resulting true/false branch or emitted values.

Next: Sass Relational Operators

Compare numbers with less-than and greater-than operators.

Relational →

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