Performance: Importing built-in modules with @use
This affects the CSS build time and the final CSS size, impacting page load speed and render time.
@use "sass:math"; .selector { width: math.div(100%, 3); }
@import "sass:math"; .selector { width: math.div(100%, 3); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| @import built-in module multiple times | N/A | N/A | Larger CSS causes slower paint | [X] Bad |
| @use built-in module once with namespace | N/A | N/A | Smaller CSS improves paint speed | [OK] Good |
@use rule do when importing built-in modules?@use@use rule imports Sass modules and gives access to their functions and variables under a namespace.@import, @use does not import raw CSS but Sass modules with scoped namespaces.@use imports modules with namespace [OK]math module using @use?@use "sass:module-name"; syntax.sass:. Others miss quotes, prefix, or use @import.@use "sass:module"; [OK]@use "sass:color";
.my-text {
color: color.scale(color.$blue, $lightness: 20%);
}.my-text?color.scale functioncolor.scale function adjusts color properties like lightness by the given percentage.$lightness: 20%color.scale with positive lightness increases brightness [OK]@use "sass:math";
.box {
width: math.percentage(0.5);
}math.percent(), not math.percentage().@use statement is correct and has a semicolon; only the function name is wrong.math.percentage() function does not exist; it should be math.percent(). -> Option Amath.percent() for percentage conversion [OK]math module to calculate the width as 75% of 1200px. Which code correctly imports the module and calculates the width?@use "sass:math"; which is correct for built-in modules.math.div(75, 100) divides 75 by 100 to get 0.75, then multiplies by 1200px for the width.math.div(75%, 100) which equals 0.75% (dividing percentage by unitless keeps %), so 0.75% * 1200px = 9px. @use "sass:math";
.container {
width: math.percent(75) * 1200px;
} uses math.percent(75) which returns 7500%.Pass the test and this pattern moves unknown