Performance: sass:math module
Using the sass:math module affects the CSS compilation speed and the final CSS size, impacting initial page load speed.
@use 'sass:math'; .my-box { $third: math.div(100, 3); width: #{$third}%; margin-left: #{$third}%; }
@use 'sass:math'; .my-box { width: calc(100% / 3); margin-left: calc(100% / 3); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using CSS calc() for simple math | 0 | 1 per affected element | Low but repeated | [!] OK |
| Using sass:math module for compile-time math | 0 | 0 | Minimal | [OK] Good |
sass:math module in Sass?sass:math module offers math functions such as rounding, max, min, and angle conversions.sass:math module in a Sass file?@use to import modules like sass:math.@import is deprecated for modules, @require and @include are invalid for imports.@use 'sass:math';
$val: math.round(4.7);
.result {
width: $val * 1rem;
}math.round(4.7) rounds 4.7 to the nearest whole number, which is 5..result { width: 5rem; }.sass:math:@use 'sass:math'; $angle: 90deg; $rad: math.deg($angle);
math.deg() converts radians to degrees; math.rad() converts degrees to radians.$angle is in degrees, but math.deg() is used, which expects radians. The correct function is math.rad().$max-width that is the maximum of three values: 300px, 25rem, and 400px. Which code correctly uses sass:math to find this maximum, assuming 1rem = 16px?Pass the test and this pattern moves unknown