Sass relational operators answer “is this number larger or smaller?” Use <, <=, >, and >= on numbers. This page covers unit conversion, unitless values, incompatible units, and five compiled examples.
01
Operators
<<=>>=
02
Returns
true / false
03
Units
Auto-convert
04
Unitless
Compares freely
05
Errors
Incompatible units
06
Practice
5 examples
Concept
What Are Relational Operators?
Official docs: relational operators determine whether numbers are larger or smaller than one another. They automatically convert between compatible units.
They work on numbers (with or without units).
Results are booleans: true or false.
Most often used inside @if, clamps, and design-token guards.
Comparison happens when Sass compiles—not in the browser.
Pair with equality (== / !=) when you need “same value” checks.
💡
Beginner tip
Think of a ruler: “Is this width at least 600px?” becomes $width >= 600px. Sass answers before CSS is written.
Foundation
📝 Syntax
styles.scss
// Less than
$a < $b
// Less than or equal
$a <= $b
// Greater than
$a > $b
// Greater than or equal
$a >= $b
Operators
Operator
Name
Returns true when…
<
less than
The first number is smaller than the second
<=
less than or equal
The first is smaller than or equal to the second
>
greater than
The first number is larger than the second
>=
greater than or equal
The first is larger than or equal to the second
Return value
Type
Result
Boolean
true or false
Compare
⚖️ Units & Automatic Conversion
Official docs: relational operators automatically convert between compatible units.
Expression
Result
Why
100 > 50
true
Plain numbers
10px < 17px
true
Same unit
96px >= 1in
true
Compatible length units convert
1000ms <= 1s
true
Compatible time units convert
Special
🔢 Unitless Numbers
Official docs: unitless numbers can be compared with any number. They are automatically converted to that number’s unit.
Expression
Result
100 > 50px
true
10px < 17
true
💡
Different from equality
With == in Dart Sass, 1 != 1px. With relational operators, unitless values can compare against unit values. Choose the operator that matches your intent.
Errors
⚠️ Incompatible Units
Official docs: numbers with incompatible units can’t be compared. Sass stops with a compile error.
styles.scss
// Error: Incompatible units px and s.
@debug 100px > 10s;
Length vs time (px vs s) fails.
Length vs angle (px vs deg) fails.
Keep both sides in the same measurement family.
Compare
🔁 Relational vs Equality
Relational
Equality
Operators
<<=>>=
==!=
Question
Larger or smaller?
Same value?
Types
Numbers only
Any Sass type
Unitless + unit
Can compare
Not equal in Dart Sass
Cheat Sheet
⚡ Quick Reference
Goal
Code
Less than
$a < $b
Less than or equal
$a <= $b
Greater than
$a > $b
Greater than or equal
$a >= $b
Breakpoint branch
@if $width >= 600px { ... }
Inclusive range
$size >= $min and $size <= $max
Compatible units
96px >= 1in → true
Inspect a boolean
meta.inspect($a > $b)
Hands-On
Examples Gallery
Each example uses relational operators at compile time. Open View Compiled CSS for verified output (booleans shown with meta.inspect).
📚 Getting Started
Official number comparisons with and without units.
Example 1 — Basic Comparisons
Plain numbers, same units, and compatible unit conversion.
Arithmetic runs first, then the relational check. Handy for asserting scale steps or guarding helper arguments.
Applications
🚀 Real-World Use Cases
Breakpoints — @if $width >= 768px for layout variants.
Clamps — keep font or spacing tokens inside a min/max range.
Token validation — reject sizes that are too small or too large.
Type scales — assert each step is larger than the previous.
Timing tokens — compare durations after converting ms and s.
🧠 How Compilation Works
1
Write a comparison
Use <, <=, >, or >= between two numbers.
Source
2
Convert compatible units
Sass aligns units (or errors if they are incompatible).
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 max-width: 100%.
Watch Out
⚠️ Common Pitfalls
Incompatible units — 100px > 10s fails at compile time.
Exclusive vs inclusive — > excludes equality; >= includes it.
Confusing with == — relational ops do not compare strings or colors.
Unitless habits — relational unitless rules differ from equality rules.
Expecting browser runtime — these operators never appear in CSS.
Pro Tips
💡 Best Practices
✅ Do
Use >= / <= for inclusive breakpoints and ranges
Keep both sides in the same unit family
Rely on automatic conversion for px/in or ms/s
Combine with and for min/max checks
Debug booleans with meta.inspect
❌ Don’t
Compare length to time or angle units
Use relational operators on strings or colors
Assume unitless rules match == behavior
Forget that equal values fail a strict > check
Expect browsers to evaluate these operators
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass relational operators
Order numbers at compile time with <, <=, >, and >=.
5
Core concepts
📝01
Operators
< <= > >=
Call
📦02
Result
true / false
Output
🔗03
Units
auto-convert
Rule
🔢04
Unitless
compares freely
Rule
✓05
Use
@if & ranges
Pattern
❓ Frequently Asked Questions
They compare whether one number is larger or smaller than another. Sass provides <, <=, >, and >=. Each returns true or false at compile time.
Yes. Sass converts between compatible units automatically. Example: 96px >= 1in is true. Comparing incompatible units like 100px > 10s causes a compile error.
Yes. Official docs: unitless numbers can be compared with any number and are automatically converted to that number’s unit. Example: 100 > 50px is true.
Equality asks whether two values are the same (any type). Relational operators only order numbers. Also, for equality in Dart Sass, 1 != 1px, but for relational comparisons a unitless number can compare with a unit value.
Use <= and >= when equal values should count as a match—for example breakpoints ($width >= 600px) or inclusive ranges ($size >= $min and $size <= $max).
No. They resolve when Sass compiles. The CSS file only keeps the resulting branch or emitted values.
Did you know?
Official Sass docs show 96px >= 1in as true—relational operators convert compatible units, and unitless numbers can compare with any unit value.
Sass relational operators <, <=, >, and >= order numbers at compile time. Lean on unit conversion, remember unitless rules, and avoid incompatible units—then drive clear @if branches and range checks.