Sass equality operators answer “are these two values the same?” Use == for equal and != for not equal. This page covers numbers (including units), strings, colors, lists, maps, booleans, and five compiled examples.
01
Operators
== / !=
02
Returns
true / false
03
Numbers
Value + units
04
Strings
Quote-insensitive
05
Lists
Separator matters
06
Practice
5 examples
Concept
What Are Equality Operators?
Official docs: equality operators return whether or not two values are the same. They are written == (equal) and != (not equal). Two values are equal if they are the same type and the same value—and “same value” depends on the type.
Results are booleans: true or false.
Most often used inside @if, guards, and helpers.
Comparison happens when Sass compiles—not in the browser.
Pair with relational operators (>, <, …) for ordering numbers.
💡
Beginner tip
Think of a checklist: “Is this theme dark?” becomes $mode == "dark". Sass answers true or false before CSS is written.
Foundation
📝 Syntax
styles.scss
// Equal — true when both sides match
$expression-a == $expression-b
// Not equal — true when the sides differ
$expression-a != $expression-b
Operators
Operator
Name
Returns true when…
==
Equal
Both sides are the same type and same value
!=
not equal
The sides differ in type or value
Return value
Type
Result
Boolean
true or false
Details
🎨 How Equality Works By Type
Type
Equal when…
Numbers
Same value and units, or equal after unit conversion
Strings
Same contents—even if one is quoted and one is not
Colors
Same color space and channels, or same legacy RGBA values
Lists
Same contents, same separator, and same bracket style
Maps
Same keys and values
true / false / null
Only equal to themselves
Calculations
Same name and arguments (operations compared textually)
Functions
Same function reference (same definition site)
Compare
⚖️ Numbers, Units & Unitless Values
Expression
Result
Why
1px == 1px
true
Same value and unit
1px != 1em
true
Incompatible units
1 != 1px
true
Unitless is not equal to with-units (Dart Sass)
96px == 1in
true
Compatible units convert
⚠️
Unitless equality (compatibility)
Official docs: LibSass and older Ruby Sass treated unitless numbers as equal to the same number with any unit. That behavior violated transitivity and was removed from modern releases. Prefer Dart Sass, where 1 != 1px.
Support
🛠 Compatibility
This is about Sass compilers, not browsers. Equality is resolved at compile time.
Implementation
== / !=
Unitless vs with units
Dart Sass
Yes
Not equal (modern rule)
LibSass
Yes
Old behavior: unitless could equal with-units
Ruby Sass
Yes
Old versions matched LibSass; fixed later
Prefer current Dart Sass so unit rules match the official docs.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Equal
$a == $b
not equal
$a != $b
Branch on a mode
@if $mode == "dark" { ... }
Quoted vs unquoted string
"Helvetica" == Helvetica → true
Compatible units
96px == 1in → true
Inspect a boolean
meta.inspect($a == $b)
Hands-On
Examples Gallery
Each example uses == / != at compile time. Open View Compiled CSS for verified output (booleans shown with meta.inspect).
📚 Getting Started
Official number and string equality samples.
Example 1 — Number Equality
Same unit, different units, unitless vs with units, and conversion.
The @if branch keeps only the dark styles. Maps compare key/value pairs. null is not the same as false.
Applications
🚀 Real-World Use Cases
Theme switches — @if $theme == "dark" for alternate palettes.
Feature flags — emit rules only when a flag is true.
Token guards — reject unexpected string or number options.
Color checks — confirm two tokens resolve to the same color.
List shape checks — ensure a helper received a space- or comma-separated list.
🧠 How Compilation Works
1
Write a comparison
Use == or != between two expressions.
Source
2
Sass compares by type rules
Applies number, string, color, list, map, and boolean rules.
Compile
3
Drive a branch or value
Feed the boolean into @if or store it for debugging.
Emit
4
✓
CSS ships
Browsers only see finished CSS like background: #111.
Watch Out
⚠️ Common Pitfalls
Unitless vs with units — in Dart Sass, 1 != 1px.
List separators — space lists are not equal to comma lists.
Brackets — [1 2] is not equal to (1 2).
null vs false — they are not equal.
Expecting browser runtime — == never appears in CSS.
Pro Tips
💡 Best Practices
✅ Do
Use == / != inside @if for clear branches
Remember quoted and unquoted strings can match
Account for unit conversion on numbers
Compare list shape (separator + brackets) intentionally
Prefer modern Dart Sass for unitless rules
❌ Don’t
Assume unitless equals with-units on Dart Sass
Ignore separators when comparing lists
Treat null as false
Expect browsers to evaluate equality
Rely on LibSass unitless quirks
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass equality
Compare values at compile time with == and !=.
5
Core concepts
📝01
Operators
== and !=
Call
📦02
Result
true / false
Output
🔗03
Numbers
units & conversion
Rule
📚04
Strings
quotes optional
Rule
✓05
Use
@if branches
Pattern
❓ 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.
Did you know?
Official Sass docs show 96px == 1in as true—equality can convert compatible units, while still keeping unitless numbers distinct from unit values in Dart Sass.
Sass equality operators == and != compare values at compile time. Learn each type’s rules—especially units, string quotes, and list separators—then drive @if branches with clear boolean results.