Reading tan() as a triangle ratio

In the previous installment we looked at why the State of CSS 2025 survey labels trigonometric functions the "Most Hated" CSS feature, and then worked through uses for cos() and sin(). This time the focus is tan(). The inverse functions — asin(), acos(), atan() and atan2() — come later in the series.

Formally, the tangent of an angle is its sine divided by its cosine. That definition is tidy but not very useful on its own; tan() earns its keep with right-angled triangles rather than circles. Pick one of the non-right angles and you get three sides: the adjacent side touching the angle, the opposite side away from it, and the hypotenuse, the longest one. The tangent is the opposite side divided by the adjacent side. Grow the opposite side and the value rises; grow the adjacent side and it falls.

Building a sectioned polygon list

A good demonstration is slicing an unordered list into triangular wedges that together form a polygon. The markup is a plain indexed list. Until sibling-index() and sibling-count() are supported, the index for each item is hardcoded as an inline CSS variable alongside a --total of 8.

The list is made a grid container that centers its items, with a --radius variable standing in for the height of each triangle. The container's width is twice --radius; each item is one --radius wide. At this point the eight rectangles simply stack and only the last is visible.

To spread them around the center, each item is rotated by 360deg divided by --total and multiplied by that item's --i. Overlap remains, so transform-origin moves to left center, which shifts each item left while rotating; a translate of half the --radius pulls it back to center before the rotation is applied. Clipping each item with clip-path gives triangular panels, though with visible gaps — reminiscent of Wheel of Fortune.

Closing those gaps means growing each item's height. Hardcoded numbers leave you recalculating by hand: an octagon with 200px-wide items wants a 166px height. Deriving the height with tan() instead keeps it maintainable. Picture four items forming a square. Each triangle is really two right triangles pressed together, and the eight right angles around the center add up to a full circle, or 360° — 45° apiece. With the angle and the adjacent side (the item width) known, the opposite side (the height) follows from tan(). Express the calculation in CSS and the correct height falls out for any radius and any item count.

Playing with transform-origin values yields further shapes. The panels can also become a circular character picker by clipping the container with clip-path: circle(50% at 50% 50%), or repurposed as a polygon image gallery. The arithmetic never changes, which is why the approach holds up in most cases.

Other authors build on the same idea: Nils Binder's diagonal layouts, Sladjana Stojanovic's tangram puzzle, Temani Afif's CSS patterns, flower shapes with mask, and border-only breadcrumbs all rely on triangles.

Where tan() breaks down on the unit circle

On the unit circle — radius of one unit — cos() returns the X coordinate and sin() the Y coordinate of a radius line rotated by some angle. A tangent line can be drawn from the radius endpoint, perpendicular to it and running outward. Two properties emerge. First, the tangent is only positive in the top-right and bottom-left quadrants, which follows from how sine and cosine divide there. Second, the value is undefined at 90° and 270°: the line becomes parallel to the X-axis and infinitely long, equally plausible in either direction. CSS has no mathematical "undefined", so it returns an unreasonably large number instead.

What remains

sin(), cos() and tan() are now covered. The inverse functions — asin(), acos(), atan() and atan2() — are the subject of the final part.