Booleans
Booleans are the logical values true
and false
. In addition their literal forms, booleans are returned by equality and relational operators, as well as many built-in functions like math.comparable()
and map.has-key()
.
You can work with booleans using boolean operators. The and
operator returns true
if both sides are true
, and the or
operator returns true
if either side is true
. The not
operator returns the opposite of a single boolean value.
Using Booleans permalinkUsing Booleans
You can use booleans to choose whether or not to do various things in Sass. The @if
rule evaluates a block of styles if its argument is true
:
The if()
function returns one value if its argument is true
and another if its argument is false
:
Truthiness and Falsiness permalinkTruthiness and Falsiness
Anywhere true
or false
are allowed, you can use other values as well. The values false
and null
are falsey, which means Sass considers them to indicate falsehood and cause conditions to fail. Every other value is considered truthy, so Sass considers them to work like true
and cause conditions to succeed.
For example, if you want to check if a string contains a space, you can just write string.index($string, " ")
. The string.index()
function returns null
if the string isn’t found and a number otherwise.
⚠️ Heads up!
Some languages consider more values falsey than just false
and null
. Sass isn’t one of those languages! Empty strings, empty lists, and the number 0
are all truthy in Sass.