Sass math.acos() Function

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
sass:math · Dart Sass 1.25+

What You’ll Learn

math.acos() is an inverse trigonometric helper in the sass:math module. Given a cosine factor, it returns the matching angle in deg. You will learn the unitless input rule, NaNdeg behavior, pairing with math.cos, Dart Sass 1.25+ notes, and five compiled examples.

01

Concept

Arccosine

02

Module

@use "sass:math"

03

Input

Unitless (−1…1)

04

Output

Angle in deg

05

Since

Dart Sass 1.25+

06

Practice

5 examples

What Is math.acos()?

Arccosine answers: which angle has this cosine? In Sass the answer is always an angle in degrees:

  • math.acos(0.5)60deg
  • math.acos(1)0deg · math.acos(0)90deg · math.acos(-1)180deg
  • math.acos(2)NaNdeg (outside the cosine range)

Official docs place it under Trigonometric Functions next to math.cos(), math.asin, and math.atan. Use acos when you already have a unitless factor and need the angle back.

💡
Beginner tip

Browsers never see math.acos. Dart Sass evaluates it and writes a plain angle (like 60deg) into your .css file—or NaNdeg if the input was invalid.

📝 Syntax

Load the math module, then pass a unitless number:

styles.scss
@use "sass:math";

math.acos($number)
// $number must be unitless → result is in deg

Parameters

ParameterTypeRequiredDescription
$numberNumberYesCosine factor. Must be unitless. Valid domain is typically -1 to 1.

Return value

TypeSituationResult
AngleInput in −1…1Arccosine in deg (0deg…180deg)
AngleInput outside −1…1NaNdeg (as in the official docs)
ErrorArgument has unitsCompile fails—pass a unitless factor

📦 Loading sass:math

styles.scss
// Recommended — namespaced
@use "sass:math";
$a: math.acos(0.5);

// Optional — bring members into the current namespace
@use "sass:math" as *;
$a: acos(0.5);

// Optional — custom namespace
@use "sass:math" as m;
$a: m.acos(0.5);
⚠️
Put @use first

Keep @use "sass:math"; near the top of the file. math.acos() needs Dart Sass 1.25+.

📏 How Units Work

Unlike math.cos() (which takes an angle), math.acos() takes a unitless factor and returns deg.

CallResultNotes
math.acos(0.5)60degOfficial example
math.acos(2)NaNdegOfficial out-of-range example
math.acos(1)0degCosine of 0°
math.acos(0)90degCosine of 90°
math.acos(-1)180degCosine of 180°
math.acos(0.5px)Error: must be unitless

🛠 Compatibility

This is about Sass compilers, not browsers. Compiled CSS receives a plain angle (or NaNdeg).

Implementationmath.acos()Notes
Dart Sass 1.25+YesPreferred; needs @use "sass:math"
Dart Sass < 1.25NoUpgrade Dart Sass
LibSass / Ruby SassNo module APIUse Dart Sass for trigonometric helpers

⚡ Quick Reference

GoalCode
Import math@use "sass:math";
Angle from cosinemath.acos(0.5)60deg
Out of rangemath.acos(2)NaNdeg
Clamp before acosmath.acos(math.clamp(-1, $n, 1))
Round-trip with cosmath.cos(math.acos(0.5))0.5
Debug while learning@debug math.acos(0.5);

📋 acos vs cos vs asin

FunctionDirectionBest for
math.acos($n)Factor → angle (deg)Recovering an angle from a cosine factor
math.cos($angle)Angle → unitless factorHorizontal projection / circular X
math.asin($n)Factor → angle (deg)Recovering an angle from a sine factor

Prefer math.acos when the known value is a cosine-like ratio. Prefer math.cos when you already know the angle.

📋 Sass math.acos() vs CSS / JS acos

Sass math.acos()CSS acos() / JS Math.acos
When it runsCompile time (Dart Sass)In the browser / runtime
Result unitAlways degJS returns radians; CSS follows CSS angle rules
Appears in CSS output?No — only the angle resultCSS acos() can stay in the stylesheet
Best forFixed factors known in SCSSDynamic factors / animated values

Examples Gallery

Each example uses @use "sass:math". Open View Compiled CSS to see what Dart Sass emits.

📚 Getting Started

Official-style acos calls and landmark values.

Example 1 — Basic math.acos()

Official docs example: arccosine of 0.5 is 60 degrees.

styles.scss
@use "sass:math";

@debug math.acos(0.5); // 60deg

.demo {
  --angle: #{math.acos(0.5)};
  rotate: math.acos(0.5);
}

How It Works

Cosine of 60° is 0.5, so arccosine of 0.5 is 60deg. The result is already an angle unit you can use in CSS.

Example 2 — Landmark Factors

Memorize the endpoints and the midpoint of the cosine range.

styles.scss
@use "sass:math";

.landmarks {
  --a1: #{math.acos(1)};   // 0deg
  --a0: #{math.acos(0)};   // 90deg
  --am1: #{math.acos(-1)}; // 180deg
}

How It Works

Valid acos results span 0deg to 180deg—the principal range of arccosine.

Example 3 — Out of Range Returns NaNdeg

Official docs show that values outside −1…1 are not real arccosines.

styles.scss
@use "sass:math";

@debug math.acos(2); // NaNdeg

.guard {
  --bad: #{math.acos(2)};
  --ok: #{math.acos(0.5)};
}

How It Works

Cosine never produces 2, so math.acos(2) becomes NaNdeg. Clamp inputs in real tokens (see example 5).

📈 Practical Patterns

Round-trips with cos and safe clamping.

Example 4 — Round-Trip with math.cos()

Recover a factor from an angle, or an angle from a factor.

styles.scss
@use "sass:math";

$factor: 0.5;
$angle: math.acos($factor);          // 60deg
$back: math.cos($angle);            // ~0.5

.orbit {
  rotate: $angle;
  --factor: #{$back};
}

How It Works

math.acos and math.cos undo each other for values in the valid cosine range (within Sass floating-point precision).

Example 5 — Clamp Before acos

Keep noisy design tokens inside −1…1 so you never ship NaNdeg.

styles.scss
@use "sass:math";

$raw: 1.2; // oops — slightly out of range
$safe: math.clamp(-1, $raw, 1);
$angle: math.acos($safe); // 0deg

.safe-rotate {
  rotate: $angle;
  --raw: #{$raw};
  --safe: #{$safe};
}

How It Works

math.clamp() pins 1.2 to 1, and math.acos(1) is 0deg instead of NaNdeg.

🚀 Real-World Use Cases

  • Recover angles — turn a stored cosine factor back into deg for rotate.
  • Design-token bridges — authors edit ratios; Sass emits angles.
  • Round-trip checks — validate that cos ↔ acos stay consistent in a scale.
  • Safe geometry — clamp factors before acos to avoid NaNdeg.
  • Teaching inverse trig — show how acos undoes cos with @debug.
  • Fixed vs animated — use Sass when the factor is known; use CSS acos() when it must change at runtime.

🧠 How Compilation Works

1

Write SCSS

Call math.acos($number) after @use.

Source
2

Require unitless

Sass rejects lengths; the value must be a bare number.

Validate
3

Compute arccosine

Return an angle in deg, or NaNdeg if out of range.

Acos
4

Plain CSS ships

The browser only receives the final angle (e.g. 60deg).

⚠️ Common Pitfalls

  • Passing angles into acos — input is a unitless factor, not deg.
  • Out-of-range factors — values outside −1…1 become NaNdeg.
  • Expecting radians — Sass acos always returns deg (unlike JS Math.acos).
  • Forgetting @usemath.acos needs sass:math loaded.
  • Old Dart Sass — need 1.25+; LibSass lacks the module API.

💡 Best Practices

✅ Do

  • Use @use "sass:math" and math.acos() in new SCSS
  • Keep inputs unitless and inside −1…1
  • Clamp noisy tokens with math.clamp(-1, $n, 1)
  • Pair with math.cos() for round-trips
  • Prefer Dart Sass 1.25+

❌ Don’t

  • Pass px / deg into math.acos
  • Ship NaNdeg from unvalidated factors
  • Expect the browser to re-evaluate math.acos
  • Assume JS-style radian output
  • Rely on LibSass for sass:math

Key Takeaways

Knowledge Unlocked

Five things to remember about math.acos()

Compile-time arccosine—unitless factor in, deg out.

5
Core concepts
📦 02

Module

sass:math

@use
🔢 03

Input

unitless

Rule
🌡️ 04

Output

always deg

Angle
05

Since

Dart Sass 1.25+

Tooling

❓ Frequently Asked Questions

math.acos($number) returns the arccosine of a unitless number in degrees. Example: math.acos(0.5) is 60deg; math.acos(2) is NaNdeg.
Add @use "sass:math"; then call math.acos($number). Requires Dart Sass 1.25+.
A unitless number, typically between -1 and 1 (the range of cosine). Lengths like px are not allowed.
An angle in deg. For valid inputs the result is between 0deg and 180deg. Out-of-range inputs return NaNdeg.
They are inverse ideas: math.cos(math.acos(0.5)) recovers about 0.5, and math.acos(math.cos(60deg)) recovers 60deg (within floating-point precision).
Official docs expose this as math.acos() on sass:math. Prefer the module form with @use "sass:math".
Did you know?

Official Sass docs show math.acos(2) as NaNdeg—not a bare NaN. The deg unit stays attached even when the numeric part is not a number.

Conclusion

math.acos() turns a unitless cosine factor into a compile-time angle in deg. Keep inputs in −1…1 (clamp when needed), pair with math.cos for round-trips, and watch for NaNdeg on invalid values.

Continue with math.cos(), math.asin(), or the Sass introduction.

More Sass Math

Continue with arcsine in the math module.

math.asin() →

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