math.atan2($y, $x) returns the 2-argument arctangent of $y and $x in deg. $y and $x must be unitless or share compatible units. Load it with @use "sass:math" on Dart Sass 1.25+.
Official fun-fact sample.
math.atan2(1, -1) is the point (-1, 1) → 135deg.
Keeps the quadrant.
Unlike math.atan(math.div($y, $x)), both signs survive. So atan2(1, -1) stays 135deg, while dividing first collapses to atan(-1) → -45deg.
Argument order is $y, then $x.
Same as JavaScript Math.atan2: vertical first, horizontal second. The Cartesian point is ($x, $y).
Syntax
Syntax
SCSS
@use "sass:math";
math.atan2($y, $x); //=> angle in deg
math.atan2(1, -1); // 135deg — point (-1, 1)
math.atan2(1, 1); // 45deg
math.atan2(0, 1); // 0deg
// Compatible length units are fine
math.atan2(10px, -10px); // 135deg
// Module API — prefer math.atan2 after @use "sass:math"
Pattern: pass separate vertical and horizontal components → get a CSS angle that respects the quadrant → use math.atan only when you already have a single unitless slope and do not need quadrant.
Reference
Quadrants and Axes
Verified Dart Sass angles for common points:
Call
Point (x, y)
Result
math.atan2(1, 1)
(1, 1) Q1
45deg
math.atan2(1, -1)
(-1, 1) Q2
135deg
math.atan2(-1, -1)
(-1, -1) Q3
-135deg
math.atan2(-1, 1)
(1, -1) Q4
-45deg
math.atan2(0, 1)
positive x-axis
0deg
math.atan2(1, 0)
positive y-axis
90deg
math.atan2(0, -1)
negative x-axis
180deg
math.atan2(-1, 0)
negative y-axis
-90deg
vs math.atan.
Official docs: math.atan(math.div(1, -1)) and math.atan(math.div(-1, 1)) both become atan(-1) → -45deg. Only atan2 keeps them apart.
Preserves quadrant — unlike dividing then calling atan.
Order is $y, $x (point is (x, y)).
Dart Sass 1.25+ via @use "sass:math".
One line: when vertical and horizontal components must stay quadrant-safe, call math.atan2($y, $x).
Practice
Compile Notes
Practical checklist:
checklist.txt
1. @use "sass:math"
2. Pass $y first, then $x (compatible units or unitless)
3. Expect a deg angle that respects the quadrant
4. Do not divide before calling atan2
5. Use math.atan only for a single known slope
Frequently Asked Questions
math.atan2($y, $x) returns the two-argument arctangent of y and x as an angle in degrees. It keeps the correct quadrant. Example: math.atan2(1, -1) is 135deg for the point (-1, 1).
$y and $x must both be unitless, or have compatible units (for example both px, or px with cm). Mixing incompatible units like px and em fails.
math.atan($n) takes one slope ratio and cannot tell quadrants apart after dividing. math.atan2($y, $x) keeps the signs of both components, so points in different quadrants stay distinct.
Like JavaScript Math.atan2, Sass uses math.atan2($y, $x)—vertical first, then horizontal. The point is (x, y) = ($x, $y).
Official docs expose this as math.atan2() on sass:math. Prefer the module form with @use "sass:math".