Sass math.cos()

Beginner
9 min read
Updated: Nov 2026
5 examples
Dart Sass 1.25+

Definition and Usage

math.cos($number) returns the cosine of $number. Pass an angle whose units are compatible with deg, or a unitless number treated as radians. The result is a unitless ratio (typically between -1 and 1). Load it with @use "sass:math" on Dart Sass 1.25+.

Official samples.

math.cos(100deg) → -0.1736481777 · math.cos(1rad) → 0.5403023059 · math.cos(1) → 0.5403023059.

Compile-time cosine.

Sass writes a fixed number into CSS. For dynamic angles (custom properties, animations), prefer CSS cos() in supporting browsers.

Unitless means radians.

math.cos(1) is not “1 degree” — it matches math.cos(1rad). Pass deg explicitly when you think in degrees.

Syntax

SCSS
@use "sass:math";

math.cos($number); //=> unitless number

math.cos(100deg); // -0.1736481777
math.cos(1rad);   // 0.5403023059
math.cos(1);      // 0.5403023059  (unitless = radians)

math.cos(0deg);   // 1
math.cos(90deg);  // 0

// Module API — prefer math.cos after @use "sass:math"

Pattern: choose an angle unit → call math.cos → multiply by a length when you need CSS offsets. Pair with math.sin, math.tan, and math.acos.

Angles and Units

How inputs are interpreted:

InputMeaningExample result
100degDegrees-0.1736481777
1radRadians0.5403023059
1 (unitless)Treated as radians0.5403023059
0degCosine of zero1
90degCosine of right angle0
180degCosine of half-turn-1
Lengths like pxNot an angleError
Result is not an angle.

Cosine is a unitless ratio. Need a length? Multiply: $r * math.cos(30deg).

SCSS Examples

Examples target Dart Sass 1.25+ with @use "sass:math". Open View Compiled CSS for verified output (matches official Sass docs samples).

Example 1 — Official Docs Sample (Degrees)

Cosine of 100deg is a small negative ratio.

SCSS
@use "sass:math";

@debug math.cos(100deg); // -0.1736481777

.basic {
  --deg: #{math.cos(100deg)};
}

How It Works

  1. Input is 100deg — an angle unit.
  2. Cosine returns a unitless number.
  3. Value is negative in the second quadrant.
  4. Matches the official Sass docs sample.

Example 2 — Radians and Unitless

Official samples: 1rad and unitless 1 match.

SCSS
@use "sass:math";

@debug math.cos(1rad); // 0.5403023059
@debug math.cos(1);    // 0.5403023059

.rad {
  --rad: #{math.cos(1rad)};
  --unitless: #{math.cos(1)};
}

How It Works

  1. 1rad is one radian.
  2. Unitless 1 is treated the same way.
  3. Both compile to 0.5403023059.
  4. Do not confuse unitless input with degrees.

Example 3 — Cardinal Angles

Familiar cosines for 0°, 90°, and 180°.

SCSS
@use "sass:math";

.angles {
  --zero: #{math.cos(0deg)};
  --ninety: #{math.cos(90deg)};
  --one-eighty: #{math.cos(180deg)};
}

How It Works

  1. cos(0deg) → 1.
  2. cos(90deg) → 0.
  3. cos(180deg) → -1.
  4. Handy as sanity checks in design-token math.

Example 4 — Round-Trip with math.acos

acos undoes cos for angles in the acos range.

SCSS
@use "sass:math";

.roundtrip {
  --back: #{math.acos(math.cos(60deg))};
}

How It Works

  1. cos(60deg) is 0.5.
  2. acos(0.5) returns 60deg.
  3. acos range is 0deg…180deg — other angles may not round-trip the same way.
  4. Use math.acos when you need the inverse.

Example 5 — Emit a Fixed CSS Ratio

Store a compile-time cosine for opacity or scale helpers.

SCSS
@use "sass:math";

$angle: 100deg;

.wave {
  --c: #{math.cos($angle)};
  opacity: math.cos(0deg);
}

How It Works

  1. Angle token is resolved at compile time.
  2. Custom property receives the unitless cosine.
  3. opacity: 1 comes from cos(0deg).
  4. Keep CSS cos() when the angle must stay dynamic.

Edge Cases & Pitfalls

Most cos bugs are treating unitless input as degrees, or expecting an angle back.

rad

Unitless = radians

math.cos(90) is not zero. Write 90deg when you mean degrees.

return

Result is unitless

Multiply by a length for CSS offsets. Cosine itself is not deg.

stage

Compile time, not runtime

Sass cannot cos a live CSS custom property. Leave CSS cos() in the stylesheet for that.

module

Module-only helper

Use math.cos after @use "sass:math".

Sass Support

Prefer the module form with Dart Sass 1.25+.

APIStatus
math.cos()Dart Sass 1.25+ via @use "sass:math"
InputAngle (deg-compatible) or unitless radians
Return typeUnitless number
LibSass / Ruby SassNo modern sass:math cos

Compile with the Dart Sass CLI.

Key Takeaways

  • Returns cosine as a unitless ratio from an angle.
  • Unitless input = radians; prefer explicit deg when needed.
  • Compile-time — CSS gets a fixed number.
  • Dart Sass 1.25+ via @use "sass:math".

One line: when an angle must become a fixed cosine ratio in CSS, call math.cos($number).

Compile Notes

Practical checklist:

checklist.txt
1. @use "sass:math"
2. Pass deg-compatible angle or unitless radians
3. Expect a unitless ratio (about -1…1)
4. Multiply by a length when you need CSS offsets
5. Use CSS cos() for runtime angles

Frequently Asked Questions

math.cos($number) returns the cosine of an angle. Example: math.cos(100deg) is about -0.1736481777; math.cos(1rad) and math.cos(1) are about 0.5403023059.
Add @use "sass:math"; then call math.cos($number). Requires Dart Sass 1.25+.
An angle compatible with deg (such as deg, rad, turn, grad), or a unitless number. Unitless values are treated as radians.
No. Cosine is a unitless ratio (typically between -1 and 1). Multiply by a length if you need a CSS length, for example $r * math.cos(30deg).
Sass math.cos() runs at compile time and writes a fixed number. CSS cos() stays in the stylesheet and can use runtime values like custom properties in supporting browsers.
Official docs expose this as math.cos() on sass:math. Prefer the module form with @use "sass:math".

Next: Sass math.div()

Divide two numbers and cancel shared units the modern way.

math.div() →

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.

8 people found this page helpful