Performance: Arithmetic operations
Arithmetic operations in Sass affect the CSS generation speed and can impact the final CSS size and complexity, influencing page load and rendering.
$base-spacing: 1rem; $gap: $base-spacing * 10 + 0.3125rem; .container { margin: $gap; }
$base-spacing: 1rem; $gap: $base-spacing * 10 + 5px; .container { margin: $gap; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mixed units arithmetic in Sass | 0 (build time only) | 0 (build time only) | Higher due to complex CSS calc() | [X] Bad |
| Consistent units arithmetic in Sass | 0 (build time only) | 0 (build time only) | Lower due to simple CSS values | [OK] Good |
10px + 5px produce?* correctly; others use invalid syntax.$width: 20px; $padding: 5px; $total: $width + $padding * 2;
$total?$height: 50px; $width: 20; $total: $height + $width;
$container-width: 1000px; $padding: 20px; $usable-width: $container-width - 2 * $padding;
$usable-width?Pass the test and this pattern moves unknown