Favorites

atan() CSS Function

atan()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The atan() function returns the arctangent of a number, as an angle between -90deg and 90deg.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The atan() CSS function calculates the arctangent (inverse tangent) of a number. It returns the angle whose tangent is the given value. The argument can be any <number>, from negative to positive infinity, and the result is an <angle> between -90deg and 90deg. For example, atan(1) is 45deg, and atan(infinity) is 90deg.

The tangent of an angle is a slope (rise over run), so atan() converts a slope back into an angle. This is useful for rotating an element so it lines up with a diagonal, when you know the ratio of height to width. If you have the two sides as separate lengths, atan2() is usually more convenient because it accepts both values and handles every direction.

The atan() function is one of the CSS trigonometric functions, together with sin(), cos(), tan(), asin(), acos(), atan() and atan2(). Like calc(), it can be used anywhere a value of the matching type is accepted, and its arguments can contain full calculations, custom properties and the constants pi and e.

/* Rotate to match a 1:1 slope (45deg) */
.diagonal {
  rotate: atan(1);
}

/* Rotate to match the slope of a 16:9 box's diagonal */
.ribbon {
  rotate: atan(9 / 16);  /* about 29.4deg */
}

Interactive Demo

Demo Code
HTML Code
<div class="demo-dial">
	<div class="demo-element"></div>
</div>
CSS Code
.demo-dial {
	position: relative;
	width: 200px;
	height: 200px;
	border-radius: 50%;
	background: repeating-conic-gradient(from 90deg, #b0b0b0 0 1deg, transparent 1deg 15deg), #f4f4f4;
	outline: 1px solid #c5c5c5;
}
.demo-dial::after {
	content: "";
	position: absolute;
	left: 100px;
	top: 100px;
	width: 100px;
	border-top: 1px dashed #4361ee;
}
.demo-element {
	position: absolute;
	left: 100px;
	top: 98px;
	width: 95px;
	height: 4px;
	border-radius: 2px;
	background: #f72585;
	transform-origin: 0 50%;
	rotate: atan(0);
}

Syntax

atan() = atan( <calc-sum> )

Values

  • <calc-sum>A calculation resolving to a <number>. The function returns an <angle> between -90deg and 90deg.

Example

<div class="wrap">
<h1>CSS atan() examples</h1>
<div class="grid">
<div class="card">
<div class="dial"><span class="needle" style="--v: 0.25"></span></div>
<div class="label">atan(0.25) &asymp; 14deg</div>
</div>
<div class="card">
<div class="dial"><span class="needle" style="--v: 1"></span></div>
<div class="label">atan(1) = 45deg</div>
</div>
<div class="card">
<div class="dial"><span class="needle" style="--v: 4"></span></div>
<div class="label">atan(4) &asymp; 76deg</div>
</div>
<div class="card">
<div class="dial"><span class="needle" style="--v: -1"></span></div>
<div class="label">atan(-1) = -45deg</div>
</div>
</div>
<p class="note">Needles are rotated counter-clockwise by the angle atan() returns.</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* atan() examples */
.dial {
position: relative;
width: 120px;
height: 120px;
margin: 0 auto;
border-radius: 50%;
background: #e2e8f0;
}

.needle {
position: absolute;
left: 50%;
top: 50%;
width: 52px;
height: 4px;
margin-top: -2px;
border-radius: 2px;
background: #dc2626;
transform-origin: left center;
}

.dial::after {
content: '';
position: absolute;
left: 50%;
top: 50%;
width: 10px;
height: 10px;
margin: -5px 0 0 -5px;
border-radius: 50%;
background: #0f172a;
}

.needle { rotate: calc(atan(var(--v)) * -1); }
Open in editor

Browser Support

The following information will show you the current browser support for the CSS atan() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee