math.ceil($number) rounds $numberup to the next highest whole number (toward +infinity). Whole numbers stay the same. Units such as px are kept. Load it with @use "sass:math" (Dart Sass 1.23+ for modules; global ceil() also exists).
Sass resolves the value when you compile. The CSS file only contains the final whole number—unlike browser CSS rounding functions.
Prefer the module form.
Global ceil() still works but is deprecated in modern Dart Sass. New stylesheets should use math.ceil after @use "sass:math".
Syntax
Syntax
SCSS
@use "sass:math";
math.ceil($number); //=> number (units preserved)
math.ceil(4); // 4
math.ceil(4.2); // 5
math.ceil(4.9); // 5
math.ceil(4.2px); // 5px
// Global name (legacy / deprecated in modern Dart Sass)
ceil(4.2); // 5
// Module API — prefer math.ceil after @use "sass:math"
Pattern: compute a fractional length or count → math.ceil so you never undershoot → compare with math.floor and math.round when the rounding direction differs.
Reference
Units and Signs
Ceiling always moves toward +infinity:
Input
Result
math.ceil(4)
4
math.ceil(4.2)
5
math.ceil(4.9)
5
math.ceil(4.2px)
5px
math.ceil(-4.2)
-4
math.ceil(-4.2px)
-4px
ceil vs floor vs round.
For 4.2: ceil → 5, floor → 4, round → 4. For -4.2: ceil → -4, floor → -5.
Rounds up to the next whole number (toward +infinity).
Keeps units such as px on the result.
Different from floor/round — pick ceil when undershoot is forbidden.
Prefer math.ceil over deprecated global ceil().
One line: when a fractional Sass number must never undershoot, call math.ceil($number).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Pass a number (units optional)
3. Expect the next whole value toward +infinity
4. Prefer math.ceil over global ceil()
5. Use floor/round when the direction differs
Frequently Asked Questions
math.ceil($number) rounds a number up to the next highest whole number. Whole numbers stay the same. For example math.ceil(4.2) is 5 and math.ceil(4) is 4. Units such as px are preserved.
Add @use "sass:math"; at the top of your SCSS file, then call math.ceil($number). Example: math.ceil(4.2px) compiles to 5px.
ceil always rounds up (toward +infinity). floor always rounds down (toward -infinity). round goes to the nearest whole number. Pick ceil when you must never undershoot—for example columns or tile counts.
Yes. Ceiling still means toward positive infinity. math.ceil(-4.2) is -4, not -5. That is different from rounding away from zero.
Yes. The global ceil($number) name still works for older stylesheets, but Dart Sass deprecates global built-ins. New projects should prefer math.ceil() from sass:math.
Same idea, different stage. Sass math.ceil() runs when you compile SCSS. CSS rounding functions run in the browser. Use Sass when the value must be fixed in the output CSS.