Sass numbers combine a numeric value with optional units. This page covers unit math, scientific notation, percentages vs decimals, precision, unit-clean habits, and five compiled examples.
01
Value
+ optional unit
02
Units
Multiply & divide
03
Convert
Compatible units
04
%
vs decimals
05
Precision
~10 digits
06
Practice
5 examples
Concept
What Are Sass Numbers?
Official docs: numbers in Sass have two components—the number itself and its units. In 16px, the number is 16 and the unit is px. Numbers can have no units, and they can have complex units built from multiplication and division.
Sass supports the same formats as CSS numbers, including scientific notation with e (for example 5.2e3). Because browser support for scientific notation has historically been uneven, Sass always compiles it to fully expanded numbers.
Unitless: 100, 0.8
Simple units: 16px, 1.5rem, 50%
Complex units: px*px, px/s (useful in Sass math; not always valid plain CSS)
No integer vs decimal split—math.div(5, 2) is 2.5
💡
Beginner tip
Think of a Sass number as “how much” plus “of what.” Keeping both parts correct lets Sass catch bad math (like adding inches to seconds) at compile time.
Official docs: Sass manipulates units like real-world calculations. Multiply two numbers and their units multiply. Divide and the result takes numerator units from the first number and denominator units from the second.
Complex units are powerful inside Sass variables and functions. Emitting them as normal CSS property values often errors on older compilers—use meta.inspect() for debugging, or keep them in Sass until units cancel to a plain CSS number.
Conversion
🔄 Compatible Units
Sass automatically converts between compatible units (CSS defines 1in as 96px). Which unit appears in the result can depend on the Sass implementation. Incompatible pairs such as 1in + 1s throw an error.
Expression
Result idea
1in + 6px
Compatible lengths → one combined length
math.div(96px, 1in)
Units cancel → unitless 1
1in + 1s
Error: incompatible units
Percentages
📈 Percentages vs Decimals
Official docs: percentages work like every other unit. They are not interchangeable with decimals, because in CSS 50% and 0.5 mean different things.
Percent → decimal: math.div($percentage, 100%)
Decimal → percent: $decimal * 100%
Explicit helper: math.percentage($decimal) (same idea as * 100%)
Precision
🔢 Precision
Official docs: Sass numbers are 64-bit floating point values. About 10 digits after the decimal matter for CSS serialization and equality. Math functions still work with the full internal value when possible so rounding errors do not pile up as quickly.
Official docs: if arithmetic gives the wrong unit, check your math. Avoid interpolation like #{$number}px—that creates an unquoted string, not a number. Prefer $number * 1px or keep px on the variable from the start.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Add a unit safely
$n * 1px
Divide with units
math.div(5px, 2s)
% → decimal
math.div(50%, 100%)
Decimal → %
0.5 * 100% or math.percentage(0.5)
Inspect a value
meta.inspect($number)
Scientific notation
5.2e3 → 5200 in CSS
Hands-On
Examples Gallery
Examples use meta.inspect() when showing Sass-only number forms. Open View Compiled CSS for verified output.
📚 Getting Started
Plain numbers, units, and scientific notation.
Example 1 — Numbers, Units & Scientific Notation
Inspect unitless values, simple units, square pixels, and e notation.
Serialization rounds for CSS output. Internal math can still use fuller precision so intermediate steps stay more accurate.
Applications
🚀 Real-World Use Cases
Spacing scales — multiply a step by 1rem or 1px.
Duration from distance — ratio units that cancel to seconds.
Opacity / progress — convert between % and unitless decimals.
Responsive math — combine compatible absolute lengths safely.
Design tokens — keep numbers typed so helpers stay unit-aware.
🧠 How Compilation Works
1
Parse the number
Read the value, optional unit, and scientific notation if present.
Parse
2
Do unit math
Multiply, divide, convert, or cancel units; error on incompatibles.
Compute
3
Serialize for CSS
Expand scientific notation and trim to serialization precision.
Write
4
✓
CSS ships
Browsers see plain lengths, times, and decimals—not Sass internals.
Watch Out
⚠️ Common Pitfalls
Interpolation for units — #{$n}px is a string, not a number.
Treating % like a decimal — 50% ≠ 0.5 in Sass.
Incompatible units — 1in + 1s fails at compile time.
Leaving complex units in CSS — cancel units or keep them Sass-only.
Assuming integer division — Sass returns decimals like JavaScript.
Pro Tips
💡 Best Practices
✅ Do
Keep units on variables from the start when possible
Use $n * 1px to attach a unit safely
Prefer math.div() for division with units
Convert percentages deliberately with unit math
Let compatible units cancel for clean CSS output
❌ Don’t
Build lengths with #{$n}px interpolation
Mix % and unitless decimals without converting
Ignore compile errors about incompatible units
Emit square pixels into normal CSS properties
Strip units unless you truly need a unitless factor
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Sass numbers
Value + unit, unit-clean math, and careful percentage conversions.
5
Core concepts
🔢01
Two parts
value + unit
Basics
⚖️02
Unit math
multiply / divide
Units
🔄03
Convert
compatible only
Safety
📈04
%
≠ decimal
Percent
✓05
Unit-clean
* 1px not #{}
Habit
❓ Frequently Asked Questions
A Sass number has two parts: the numeric value and optional units. For example, in 16px the value is 16 and the unit is px. Numbers can also be unitless.
No. 50% is a number with a % unit and is not the same as 0.5. Convert with math.div($percentage, 100%) or $decimal * 100% (or math.percentage()).
Interpolation creates an unquoted string that looks like a number but cannot be used with number math or functions. Prefer $number * 1px or keep the unit on the variable.
Sass converts compatible units automatically (for example 1in + 6px). Combining incompatible units such as 1in + 1s throws a compile error.
Sass uses 64-bit floats internally and serializes with up to about 10 digits after the decimal for CSS output and equality checks.
No. Sass does not distinguish whole numbers from decimals. math.div(5, 2) returns 2.5—similar to JavaScript.
Did you know?
Official Sass docs note that if you get the wrong unit from arithmetic, you are probably missing a unit somewhere—staying unit-clean turns Sass into a helpful error checker for your design math.
Sass numbers are value-plus-unit building blocks. Use unit-clean math, convert percentages deliberately, and let compatible units cancel into plain CSS values browsers understand.