Favorites

cos() CSS Function

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

The cos() function returns the cosine of an angle, a number between -1 and 1, useful for placing items in a circle.

☕
Enjoying this site?

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

Buy us a coffee

Description

The cos() CSS function calculates the cosine of an angle. The argument is an <angle> or a plain number (radians), and the result is a <number> between -1 and 1. For example, cos(0deg) is 1, cos(60deg) is 0.5 and cos(90deg) is 0.

Cosine gives the horizontal position of a point on a circle. Used together with sin(), which gives the vertical position, it lets you arrange elements in a circle, such as a radial menu, clock numbers or icons around an avatar. Each item only needs an angle, and the coordinates are calculated by the browser.

The cos() 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.

.ring {
  --radius: 90px;
  position: relative;
}

/* Place each item around a circle */
.ring .item {
  position: absolute;
  left: calc(50% + cos(var(--angle)) * var(--radius));
  top: calc(50% + sin(var(--angle)) * var(--radius));
  translate: -50% -50%;
}

Interactive Demo

050px100px150px200px250px
Demo Code
HTML Code
<div class="demo-track">
	<div class="demo-element"></div>
</div>
<div class="demo-scale"><span>0</span><span>50px</span><span>100px</span><span>150px</span><span>200px</span><span>250px</span></div>
CSS Code
.demo-track {
	width: 300px;
	height: 36px;
	background: #f4f4f4 repeating-linear-gradient(90deg, #b0b0b0 0 1px, transparent 1px 50px);
	outline: 1px solid #c5c5c5;
}
.demo-scale {
	display: grid;
	grid-template-columns: repeat(6, 50px);
	width: 300px;
	font-size: 11px;
	color: #666;
}
.demo-element {
	height: 100%;
	background: linear-gradient(90deg, #f72585, #b5179e);
	width: calc(cos(60deg) * 300px);
}

Syntax

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

Values

  • <calc-sum>A calculation resolving to an <angle> or a <number> (interpreted as radians). The function returns a <number> from -1 to 1.

Example

<div class="wrap">
<h1>CSS cos() examples</h1>
<div class="card"><div class="ring">
<span class="item" style="--i: 0">1</span>
<span class="item" style="--i: 1">2</span>
<span class="item" style="--i: 2">3</span>
<span class="item" style="--i: 3">4</span>
<span class="item" style="--i: 4">5</span>
<span class="item" style="--i: 5">6</span>
<span class="item" style="--i: 6">7</span>
<span class="item" style="--i: 7">8</span>
</div></div>
<p class="note">left uses cos(var(--angle)) and top uses sin(var(--angle)).</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;
}

/* cos() examples */
.ring {
--radius: 90px;
position: relative;
width: 240px;
height: 240px;
margin: 0 auto;
border-radius: 50%;
background: #e2e8f0;
}

.item {
position: absolute;
width: 36px;
height: 36px;
border-radius: 50%;
display: grid;
place-items: center;
background: #2563eb;
color: #fff;
font-size: 13px;
font-weight: 700;
--angle: calc(var(--i) * 45deg - 90deg);
left: calc(50% + cos(var(--angle)) * var(--radius));
top: calc(50% + sin(var(--angle)) * var(--radius));
translate: -50% -50%;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS cos() 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