LibSass and older versions of Ruby Sass consider numbers without units to be equal to the same numbers with any units. This behavior was deprecated and has been removed from more recently releases because it violates transitivity.
The equality operators return whether or not two values are the same. They’re written <expression> == <expression>
, which returns whether two expressions are equal, and <expression> != <expression>
, which returns whether two expressions are not equal. Two values are considered equal if they’re the same type and the same value, which means different things for different types:
true
, false
, and null
are only equal to themselves.@debug 1px == 1px; // true @debug 1px != 1em; // true @debug 1 != 1px; // true @debug 96px == 1in; // true @debug "Helvetica" == Helvetica; // true @debug "Helvetica" != "Arial"; // true @debug hsl(34, 35%, 92.1%) == #f2ece4; // true @debug rgba(179, 115, 153, 0.5) != rgba(179, 115, 153, 0.8); // true @debug (5px 7px 10px) == (5px 7px 10px); // true @debug (5px 7px 10px) != (10px 14px 20px); // true @debug (5px 7px 10px) != (5px, 7px, 10px); // true @debug (5px 7px 10px) != [5px 7px 10px]; // true $theme: ("venus": #998099, "nebula": #d2e1dd); @debug $theme == ("venus": #998099, "nebula": #d2e1dd); // true @debug $theme != ("venus": #998099, "iron": #dadbdf); // true @debug true == true; // true @debug true != false; // true @debug null != false; // true @debug get-function("rgba") == get-function("rgba"); // true @debug get-function("rgba") != get-function("hsla"); // true
@debug 1px == 1px // true @debug 1px != 1em // true @debug 1 != 1px // true @debug 96px == 1in // true @debug "Helvetica" == Helvetica // true @debug "Helvetica" != "Arial" // true @debug hsl(34, 35%, 92.1%) == #f2ece4 // true @debug rgba(179, 115, 153, 0.5) != rgba(179, 115, 153, 0.8) // true @debug (5px 7px 10px) == (5px 7px 10px) // true @debug (5px 7px 10px) != (10px 14px 20px) // true @debug (5px 7px 10px) != (5px, 7px, 10px) // true @debug (5px 7px 10px) != [5px 7px 10px] // true $theme: ("venus": #998099, "nebula": #d2e1dd) @debug $theme == ("venus": #998099, "nebula": #d2e1dd) // true @debug $theme != ("venus": #998099, "iron": #dadbdf) // true @debug calc(10px + 10%) == calc(10px + 10%) // true @debug calc(10% + 10px) == calc(10px + 10%) // false @debug true == true // true @debug true != false // true @debug null != false // true @debug get-function("rgba") == get-function("rgba") // true @debug get-function("rgba") != get-function("hsla") // true
© 2006–2022 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/operators/equality