GO-V.ORG
As seen in

`atan2()` CSS function

The atan2() CSS function is a trigonometric function that returns the inverse tangent of two values between -infinity and infinity. The function accepts two arguments and returns an angle between -180deg and 180deg, without implying any specific unit such as radians.

The **`atan2()`** [CSS](/docs/Web/CSS) [function](/docs/Web/CSS/Reference/Values/Functions) is a trigonometric function that returns the inverse tangent of two values between `-infinity` and `infinity`. The function accepts two arguments and returns an angle between `-180deg` and `180deg`, without implying any specific unit such as radians.

## Syntax

```css
/* Two <number> values */
transform: rotate(atan2(3, 2));

/* Two <dimension> values */
transform: rotate(atan2(1rem, -0.5rem));

/* Two <percentage> values */
transform: rotate(atan2(20%, -30%));

/* Other values */
transform: rotate(atan2(pi, 45));
transform: rotate(atan2(e, 30));
```

### Parameters

The `atan2(y, x)` function accepts two comma-separated values as its parameters. Each value can be a &lt;number&gt;, a &lt;dimension&gt;, or a &lt;percentage&gt;. Both values must be of the same type, although if they are &lt;dimension&gt; they can be of different units (example: `atan2(100px, 5vw)` is valid).

- `y`
- : The y-coordinate of the point. A calculation which resolves to a &lt;number&gt;, a &lt;dimension&gt;, or a &lt;percentage&gt;.
- `x`
- : The x-coordinate of the point. A calculation which resolves to a &lt;number&gt;, a &lt;dimension&gt;, or a &lt;percentage&gt;.

### Return value

Given two values `x` and `y`, the function `atan2(y, x)` calculates and returns the angle between the positive x-axis and the ray from the origin to the point `(x, y)`.

## Formal syntax

## Examples

### Rotate elements

The `atan2()` function can be used to rotate elements as it returns an angle.

#### HTML

```html
<div class="box box-1"></div>
<div class="box box-2"></div>
<div class="box box-3"></div>
<div class="box box-4"></div>
<div class="box box-5"></div>
```

#### CSS

```css hidden
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 50px;
}
```

```css
div.box {
width: 100px;
height: 100px;
background: linear-gradient(orange, red);
}
div.box-1 {
transform: rotate(atan2(3, 2));
}
div.box-2 {
transform: rotate(atan2(3%, -2%));
}
div.box-3 {
transform: rotate(atan2(-1, 0.5));
}
div.box-4 {
transform: rotate(atan2(1, 0.5));
}
div.box-5 {
transform: rotate(atan2(1rem, -0.5rem));
}
```

#### Result

100%

## Specifications

## Browser compatibility

## See also

- sin
- cos
- tan
- asin
- acos
- atan
- [Using CSS typed arithmetic](/docs/Web/CSS/Guides/Values_and_units/Using_typed_arithmetic)

source: MDN Web Docs mirror · page

Cite this

"`atan2()` CSS function". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/atan2

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·