Home Sass Operators Equality Sass Equality Operators Definition
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
Syntax $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 .
Code
SCSS Examples Open View Compiled CSS for verified Dart Sass output (matches official Sass docs samples where shown).
1. Numbers 2. Strings 3. Lists 4. null 5. @if Example 1 — Official Number Samples Same units, different units, unitless vs px, and conversion.
@use "sass:meta";
.probe {
--a: #{meta.inspect(1px == 1px)};
--b: #{meta.inspect(1px != 1em)};
--c: #{meta.inspect(1 != 1px)};
--d: #{meta.inspect(96px == 1in)};
} .probe {
--a: true;
--b: true;
--c: true;
--d: true;
} How It Works 1px == 1px same value and unit.1px != 1em incompatible units.1 != 1px unitless is not a length.96px == 1in converts and matches.Example 2 — Quoted vs Unquoted Strings Quote state does not break content equality.
@use "sass:meta";
.strings {
--a: #{meta.inspect("Helvetica" == Helvetica)};
--b: #{meta.inspect("Helvetica" != "Arial")};
} .strings {
--a: true;
--b: true;
} How It Works Same letters → equal.Quotes are not part of the comparison.Different names → not equal.Matches the official string samples.Example 3 — List Separators & Brackets Same items can still be unequal if the list form differs.
@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])};
} .lists {
--a: true;
--b: true;
--c: true;
} How It Works Identical space lists are equal.Comma vs space is a different list.Brackets change equality too.Matches the official list samples.Example 4 — null Is Not false true, false, and null only equal themselves.
@use "sass:meta";
.bools {
--a: #{meta.inspect(true == true)};
--b: #{meta.inspect(true != false)};
--c: #{meta.inspect(null != false)};
} .bools {
--a: true;
--b: true;
--c: true;
} How It Works true == true holds.true != false holds.null != false — both are falsey, but not equal.Use == when you need the exact value, not just truthiness.Example 5 — Branch with @if Compare a theme token and emit different CSS.
$theme: "dark";
.card {
@if $theme == "dark" {
color: #eee;
} @else {
color: #111;
}
} How It Works == returns a boolean at compile time.@if keeps only the matching branch.Browsers never see the comparison.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.
Toolchain
Sass Support Equality is core SassScript on Dart Sass.
Operator Meaning ==True when both sides are equal !=True when both sides are not equal Unitless equality Dart Sass: unitless ≠ unit-bearing (LibSass differed) Return type Boolean (true / false)
Compile with the Dart Sass CLI .
Remember
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.
Practice
Compile Notes Practical checklist:
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 What are Sass equality operators? Sass provides == (equal) and != (not equal). They return true or false at compile time by comparing two values.
When are two numbers equal? 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.
Are quoted and unquoted strings equal? Yes, if the contents match. Official docs: "Helvetica" == Helvetica is true.
Do list separators matter? 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.
Is null equal to false? No. Official docs: null != false is true. true, false, and null are only equal to themselves.
Does equality run in the browser? 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 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