Catalog / Sass Cheatsheet
Sass Cheatsheet
A comprehensive cheat sheet covering Sass syntax, variables, mixins, functions, and more, designed to help you write cleaner and more maintainable CSS.
Sass Basics
Variables
Defining Variables |
Variables in Sass start with a
|
Using Variables |
Variables can be used throughout your Sass code.
|
Scope |
Variables have scope. Variables defined inside a block (e.g., a mixin or a selector) are only accessible within that block unless made global with
|
Nesting
Nesting Selectors |
Sass allows you to nest CSS selectors, following the HTML structure.
|
|
The
|
Nesting Properties |
You can also nest properties that share the same namespace.
|
Mixins
Defining Mixins |
Mixins allow you to define reusable styles. Use
|
Including Mixins |
Include mixins in your CSS rules.
|
Mixins with Arguments |
Mixins can accept arguments.
|
Default Arguments |
You can also define default values for mixin arguments.
|
Sass Functions
Color Functions
rgba() |
Creates a color with red, green, blue, and alpha values.
|
mix() |
Mixes two colors together.
|
darken(), lighten() |
Adjusts the lightness of a color.
|
saturate(), desaturate() |
Adjusts the saturation of a color.
|
grayscale() |
Converts a color to grayscale.
|
adjust-hue() |
Adjusts the hue of a color.
|
complement() |
Returns the complementary color.
|
String Functions
quote(), unquote() |
Adds or removes quotes from a string.
|
to-upper-case(), to-lower-case() |
Converts a string to upper or lower case.
|
str-length() |
Returns the length of a string.
|
str-insert() |
Inserts a substring into a string at a specified position.
|
str-slice() |
Extracts a substring from a string.
|
Number Functions
percentage() |
Converts a number to a percentage.
|
round(), ceil(), floor() |
Rounds a number to the nearest integer.
|
abs() |
Returns the absolute value of a number.
|
min(), max() |
Returns the minimum or maximum of a set of numbers.
|
random() |
Returns a random number.
|
Directives and Control Structures
Import and Use
@import |
The
|
@use |
The
|
@forward |
The
|
Control Directives
@if, @else if, @else |
Conditional statements.
|
@for |
For loops.
|
@each |
Each loops for lists and maps.
|
@while |
While loops.
|
Other Directives
@extend |
Shares the styles of one selector with another.
|
@at-root |
Causes one or more rules to be emitted at the root of the document.
|
@debug |
Prints a SassScript expression to the standard error output stream. Useful for debugging.
|
@warn |
Prints a warning to the standard error output stream.
|
@error |
Causes Sass to emit a fatal error and halt compilation.
|
Data Types and Operators
Data Types
Numbers |
Integers and decimals.
|
Strings |
Sequences of characters.
|
Colors |
Color values.
|
Booleans |
|
Null |
Represents the absence of a value.
|
Lists |
Ordered sequences of values.
|
Maps |
Key-value pairs.
|
Operators
Arithmetic Operators |
|
Relational Operators |
|
Equality Operators |
|
Logical Operators |
|
String Operators |
|