CSS Trigonometric Functions

CSS 삼각함수

Trigonometric functions — `sin()`, `cos()`, `atan2()` — usable directly inside CSS calculations, for circular layouts and clock hands without JS.

Also known as: sin() cos() tan()CSS trig
···
html
<div class="wrap">
  <div class="badge" id="badge"><svg viewBox="0 0 10 10"><path id="bpath" d="M1.5 5.2l2.6 2.6L8.5 2.4" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg><span id="btext">확인 중</span></div>
  <div class="ring" id="ring">
    <div class="dot" style="--i:0"></div><div class="dot" style="--i:1"></div><div class="dot" style="--i:2"></div>
    <div class="dot" style="--i:3"></div><div class="dot" style="--i:4"></div><div class="dot" style="--i:5"></div>
  </div>
</div>
css
.wrap{position:relative;width:100%;height:100%;display:grid;place-items:center}
.ring{position:relative;width:110px;height:110px;animation:spin 8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.dot{position:absolute;top:50%;left:50%;width:12px;height:12px;border-radius:50%;background:var(--accent);
  translate: calc(cos(calc(var(--i) * 60deg)) * 48px - 6px) calc(sin(calc(var(--i) * 60deg)) * 48px - 6px)}
.ring.fallback .dot{translate:0 0}
.badge{position:absolute;top:0;right:0;display:flex;align-items:center;gap:5px;padding:4px 9px;border-radius:999px;font-size:10px;font-weight:700;background:var(--bg);border:1px solid var(--line);color:var(--accent-3);z-index:2}
.badge.no{color:var(--accent-2)}
.badge svg{width:9px;height:9px}
js
const ok = CSS.supports('width', 'calc(cos(45deg) * 1px)');
const b=document.getElementById('badge'),p=document.getElementById('bpath'),t=document.getElementById('btext');
b.classList.toggle('no', !ok);
p.setAttribute('d', ok ? 'M1.5 5.2l2.6 2.6L8.5 2.4' : 'M2 2l6 6M8 2l-6 6');
t.textContent = ok ? 'CSS 삼각함수 지원됨' : '미지원 · JS Math 폴백';
const ring = document.getElementById('ring');
if (!ok) {
  ring.classList.add('fallback');
  [...ring.children].forEach((dot, i) => {
    const a = i * 60 * Math.PI / 180;
    dot.style.transform = `translate(${Math.cos(a) * 48 - 6}px, ${Math.sin(a) * 48 - 6}px)`;
  });
}

Placing icons evenly around a circle, or computing a clock hand's angle, has classically been JS's job — `Math.sin`/`Math.cos`. CSS `calc()` only did arithmetic, so the moment an angle needed to become a coordinate, you reached for JS.

CSS trig functions let `sin()`, `cos()`, `tan()`, `asin()`, `acos()`, `atan()`, and `atan2()` live inside `calc()`. Pass an angle through a custom property — `transform: translate(calc(cos(var(--a)) * 50px), calc(sin(var(--a)) * 50px))` — and circular layouts or a rotating clock hand become pure CSS.

Check caniuse/MDN baseline for support. Without it, computing each element's `left`/`top` (or `transform`) with `Math.cos`/`Math.sin` in JS and writing it as an inline style is the fallback.

When to use

Arranging icons in a circle, or computing a clock/gauge needle angle in pure CSS.