Built-in Modules
|
This section documents Sass/SCSS as implemented by Dart Sass, the current official and actively maintained compiler — it is not tied to any specific book, build tool, or CSS framework (Bootstrap, Bulma, etc.). Unlike the other reference sections on this site, no single reference book underpins it: the content was generated with the assistance of AI from general knowledge of Dart Sass, and should be verified against the current official documentation at sass-lang.com before relying on it in production. Sass continues to evolve, so behaviour described here may lag the compiler you are actually running. This section’s bibliography lists the reference material consulted while preparing these pages. |
Sass ships a standard library organised into modules with the sass: prefix. Each is loaded with @use like
any other module (see Partials & Modules), and its members are reached
through a namespace:
@use "sass:math";
@use "sass:color";
@use "sass:map";
.button {
width: math.div(100%, 3);
background: color.adjust(#3f51b5, $lightness: -10%);
border-radius: map.get($radii, md);
}
Built-in modules need no file path and are always available — there is nothing to install. As with any @use,
they can be aliased (@use "sass:math" as m;) or loaded unnamespaced (@use "sass:math" as *;), though the
namespace is short enough that keeping it is usually clearer.
The modules at a glance
| Module | Purpose | Most commonly used |
|---|---|---|
|
Numeric operations, rounding, units |
|
|
Inspect and transform colours |
|
|
Operate on lists |
|
|
Operate on maps |
|
|
Quoting, slicing, and building strings |
|
|
Inspect and manipulate selectors |
|
|
Introspection and metaprogramming |
|
sass:math
| Function | Description | Example |
|---|---|---|
|
Division — the required replacement for |
|
|
Unitless fraction → percentage |
|
|
Nearest whole number |
|
|
Round up / down |
|
|
Absolute value |
|
|
Smallest / largest |
|
|
Constrain to a range |
|
|
Square root / exponent |
|
|
Euclidean length |
|
|
Whether |
|
|
Whether units can be combined |
|
|
The unit as a string |
|
Constants: math.$pi, math.$e. Trigonometric functions (math.sin(), math.cos(), math.atan2(), …) take
and return angle units.
@use "sass:math";
@function rem($px, $base: 16px) {
@return math.div($px, $base) * 1rem;
}
.col-4 { width: math.percentage(math.div(4, 12)); } // 33.3333333333%
Note that math.min()/math.max() are distinct from CSS’s own min()/max(), which the browser evaluates at
runtime. Sass will pass through an unquoted min(…)/max(…) containing units it cannot reconcile, but
being explicit with the math. namespace avoids the ambiguity entirely.
sass:color
| Function | Description | Example |
|---|---|---|
|
Add to a channel ( |
|
|
Scale a channel proportionally toward its limit |
|
|
Set a channel to an absolute value |
|
|
Blend two colours |
|
|
Inverse colour |
|
|
Desaturate fully |
|
|
Hue rotated 180° |
|
|
Read one channel (from the given colour space) |
|
The three transformation functions differ in a way worth understanding:
-
color.adjust()adds a fixed amount:$lightness: -10%subtracts 10 percentage points. -
color.scale()moves a fraction of the remaining distance to the limit:$lightness: 40%closes 40% of the gap to white. This degrades gracefully and never overshoots, which makes it the better choice for deriving a palette. -
color.change()sets the channel outright, ignoring its current value.
@use "sass:color";
$brand: #3f51b5;
.button {
background: $brand;
&:hover { background: color.adjust($brand, $lightness: -8%); }
&:disabled { background: color.change($brand, $alpha: 0.4); }
}
.button--subtle { background: color.scale($brand, $lightness: 70%); }
The older global colour functions — lighten(), darken(), saturate(), desaturate(), opacify(),
transparentize(), fade-out() — are deprecated in favour of color.adjust()/color.scale(). They are
also easy to misuse: darken($c, 20%) subtracts 20 points of lightness regardless of the starting colour, so it
turns a near-black into pure black rather than something merely darker. Prefer color.scale().
sass:list
| Function | Description | Example |
|---|---|---|
|
Element at 1-based index |
|
|
Element count |
|
|
Index of |
|
|
New list with |
|
|
Concatenate |
|
|
Combine element-wise |
|
|
|
|
|
Slash-separated list |
|
See Lists & Maps for worked examples and the 1-indexing caveat.
sass:map
| Function | Description | Example |
|---|---|---|
|
Value for a key (or nested key path), else |
|
|
New map with the key set |
|
|
Combine; |
|
|
New map without those keys |
|
|
Key presence |
|
|
Comma list of keys |
|
|
Comma list of values |
|
sass:string
| Function | Description | Example |
|---|---|---|
|
Add quotes |
|
|
Remove quotes |
|
|
Character count |
|
|
1-based position of |
|
|
Substring (1-based, inclusive) |
|
|
Insert at index |
|
|
Uppercase |
|
|
Lowercase |
|
|
A random unique unquoted string |
|
string.unquote() matters when building a value that must not carry quotes in the output:
@use "sass:string";
$family: "Inter";
.a { font-family: string.unquote($family), sans-serif; }
Note that strings are also 1-indexed, and `string.slice()’s end index is inclusive — both differ from most other languages.
sass:selector
Rarely needed, but useful when writing a mixin that must reason about where it was included.
| Function | Description |
|---|---|
|
Combine selectors as if nested |
|
Concatenate without a combinator (like |
|
A selector matching both, or |
|
Whether |
|
A selector string as a list structure |
|
Substitute within a selector |
sass:meta
| Function | Description | Example |
|---|---|---|
|
Type name |
|
|
Debug string of any value (maps included) |
|
|
Named args of a variadic mixin/function, as a map |
see Mixins |
|
Whether a variable is defined |
|
|
Whether a mixin is defined |
|
|
Whether a function is defined |
|
|
A first-class function reference |
|
|
Invoke a function reference |
|
|
Load a module’s CSS dynamically |
|
meta.inspect() is the practical everyday one — it is the only way to print a map or list legibly:
@use "sass:meta";
@debug meta.inspect($breakpoints); // (sm: 576px, md: 768px, lg: 992px)
Global functions are deprecated
Before the module system, every built-in was a single global function: nth(), map-get(), darken(),
str-length(), type-of(), and so on. These still work for backwards compatibility but are deprecated;
new code should use the namespaced module forms.
| Global (deprecated) | Module form |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A handful of functions remain global because they are not part of any module:
-
rgb(),rgba(),hsl(),hsla()— not deprecated; these mirror the CSS functions of the same names. -
if($condition, $if-true, $if-false)— lazily evaluates only the branch it returns, but is itself now deprecated in favor of the modern CSSif()syntax (if(sass($condition): $if-true; else: $if-false)); see the deprecation notice.
The sass-migrator tool can convert global calls to module calls automatically:
sass-migrator module --migrate-deps scss/main.scss