Sass Numbers

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 5 Examples
Values & units

What You’ll Learn

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

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.

📝 Syntax

styles.scss
$count: 100;        // unitless
$opacity: 0.8;      // unitless decimal
$size: 16px;        // length
$ratio: 5px * 2px;  // complex unit (square pixels)

⚖️ How Units Work

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.

styles.scss
@use "sass:math";
@use "sass:meta";

.demo {
  --square: #{meta.inspect(4px * 6px)};           // 24px*px
  --speed: #{meta.inspect(math.div(5px, 2s))};    // 2.5px/s
  --cancel: #{meta.inspect(math.div(96px, 1in))}; // 1 (units cancel)
}
💡
Heads up

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.

🔄 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.

ExpressionResult idea
1in + 6pxCompatible lengths → one combined length
math.div(96px, 1in)Units cancel → unitless 1
1in + 1sError: incompatible units

📈 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

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.

styles.scss
@use "sass:meta";

.demo {
  --trimmed: #{meta.inspect(0.012345678912345)}; // 0.0123456789
}

✅ Stay Unit-Clean

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.

⚡ Quick Reference

GoalCode
Add a unit safely$n * 1px
Divide with unitsmath.div(5px, 2s)
% → decimalmath.div(50%, 100%)
Decimal → %0.5 * 100% or math.percentage(0.5)
Inspect a valuemeta.inspect($number)
Scientific notation5.2e35200 in CSS

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.

styles.scss
@use "sass:meta";

.demo {
  --n1: #{meta.inspect(100)};
  --n2: #{meta.inspect(0.8)};
  --n3: #{meta.inspect(16px)};
  --n4: #{meta.inspect(5px * 2px)};
  --sci1: #{meta.inspect(5.2e3)};
  --sci2: #{meta.inspect(6e-2)};
}

How It Works

Scientific notation expands fully (5.2e35200). 5px * 2px keeps a complex unit you can inspect in Sass.

Example 2 — Compatible Units & Percentage Math

Convert inches and pixels, then flip between % and decimals.

styles.scss
@use "sass:math";
@use "sass:meta";

.demo {
  --compat: #{meta.inspect(1in + 6px)};
  --pct-dec: #{meta.inspect(math.div(50%, 100%))};
  --dec-pct: #{meta.inspect(0.5 * 100%)};
  --pct-fn: #{meta.inspect(math.percentage(0.5))};
}

How It Works

1in + 6px becomes one length. Percentage helpers prove 50%0.5 until you convert deliberately.

📈 Ratios, Strings & Precision

Real transition math, the interpolation trap, and digit trimming.

Example 3 — Unit Ratio for Transition Timing

Official-docs style: seconds per pixel cancels with a pixel distance to yield seconds.

styles.scss
@use "sass:math";

$transition-speed: math.div(1s, 50px);

@mixin move($left-start, $left-stop) {
  position: absolute;
  left: $left-start;
  transition: left ($left-stop - $left-start) * $transition-speed;

  &:hover {
    left: $left-stop;
  }
}

.slider {
  @include move(10px, 120px);
}

How It Works

Distance is 110px. Times 1s / 50px cancels px and leaves 2.2s—plain CSS that browsers understand.

Example 4 — #{$n}px Creates a String

Looks like 16px, but meta.type-of proves it is not a number.

styles.scss
@use "sass:meta";

$n: 16;

.unit-clean {
  width: $n * 1px;
}

.bad-string {
  --fake: #{$n}px;
  --type: #{meta.type-of(#{$n}px)};
}

.good-number {
  --real: #{meta.inspect($n * 1px)};
  --type: #{meta.type-of($n * 1px)};
}

How It Works

Both look identical in CSS text, but only $n * 1px remains a Sass number you can multiply, divide, or pass to math functions.

Example 5 — Ten-Digit Serialization

Extra digits beyond the usual precision are trimmed when the value is written out.

styles.scss
@use "sass:meta";

.precision {
  --a: #{meta.inspect(0.012345678912345)};
  --b: #{meta.inspect(0.99999999991)};
  --c: #{meta.inspect(1.00000000009)};
}

How It Works

Serialization rounds for CSS output. Internal math can still use fuller precision so intermediate steps stay more accurate.

🚀 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.

⚠️ Common Pitfalls

  • Interpolation for units#{$n}px is a string, not a number.
  • Treating % like a decimal50%0.5 in Sass.
  • Incompatible units1in + 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.

💡 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Sass numbers

Value + unit, unit-clean math, and careful percentage conversions.

5
Core concepts
⚖️ 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.

Conclusion

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.

Continue with Sass Strings or numeric operators.

Next: Sass Strings

Learn quoted vs unquoted strings, escapes, and indexes.

Sass Strings →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful