Morphing Shapes With clip-path: polygon(): Point-Matched Transitions
Shape morphs are a staple of expressive interfaces: a play triangle folding into a pause pair, a hamburger becoming a cross, a square badge blooming into a star when an achievement unlocks. SVG path animation can do this but pulls icons out of CSS and usually into a script. clip-path: polygon() can do most of it in plain CSS, with one strict rule — both shapes must have the same number of points — and one subtle one — the points must correspond sensibly. This page shows how to satisfy both and build morphs that stay clean at every in-between frame. It sits in Clip-Path & Mask Animations within the CSS-Only Micro-Interactions & Animations guide.
Why morph with clip-path
Clipping an element to a polygon turns any box — a coloured <span>, an image, a gradient — into that shape, and the browser interpolates between two polygons vertex by vertex. That makes shape changes a property transition like any other: triggered by :hover, :checked, :focus-visible or a class, timed with transition, eased with any timing function, and cancellable mid-flight.
The alternatives each have costs. Swapping two icons with opacity produces a cross-fade, not a morph. Animating an SVG path's d attribute works in some engines and requires identical command structures, which is harder to author than a point list. Transforming multiple bars, the classic hamburger technique, needs several elements and careful transform origins. For solid, flat, straight-edged shapes, a clipped polygon is usually the least code.
Morphs carry meaning, so the accessibility rule is to never let the shape be the only carrier of state. A morphing play button must also change its accessible name.
The two rules of polygon interpolation
Rule one: equal counts. polygon() interpolates only between polygons with the same number of vertices. A triangle has three; a hexagon has six. To morph between them, the triangle must be written with six points. Duplicate points placed on top of each other are perfectly valid — they draw a zero-length edge — and during the morph they separate and travel to their own destinations.
Rule two: corresponding order. Point n travels in a straight line to point n. If both lists start at the top and go clockwise, every point has a short, sensible path. If one starts at the top and the other at the left, points cross paths mid-animation and the shape twists into a bow tie before resolving. Always pick a common start position and direction.
Where to place the padding points matters too. The triangle above doubles each corner, so as the morph runs each corner splits into two hexagon vertices. Padding all three extras at a single corner would instead make that corner explode outward while the others barely move — occasionally a desired effect, usually not.
The complete implementation
The toggle below morphs a play triangle into a pause symbol and back. The pause symbol is two bars, which as a single polygon is a shape with a notch cut into it — eight points drawn as one outline. The triangle is padded to eight points to match.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Play to pause morph</title>
<style>
body { font: 16px/1.5 system-ui, sans-serif; margin: 2rem; }
.player { display: inline-flex; align-items: center; gap: 0.75rem; cursor: pointer; }
/* The checkbox is the state. It stays in the accessibility tree, just
visually hidden, so it is focusable and announced. */
.player input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.player__icon {
width: 3rem;
height: 3rem;
background: #4f46e5;
/* PLAY: a right-pointing triangle written with 8 points, in the same
order as the pause outline below. Points 3-4 and 2-5 coincide, so
the outline runs down a zero-width slit at x=50% and back up. */
clip-path: polygon(
20% 10%, 50% 27.5%, 50% 72.5%, 50% 72.5%,
50% 27.5%, 85% 50%, 85% 50%, 20% 90%
);
transition: clip-path 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}
/* PAUSE: two bars as ONE outline: down the left bar, along the bottom
to the right bar, up and round it, then back along the bottom edge.
The two bottom runs overlap with zero width, so the gap stays empty. */
.player input:checked + .player__icon {
clip-path: polygon(
20% 10%, 42% 10%, 42% 90%, 58% 90%,
58% 10%, 80% 10%, 80% 90%, 20% 90%
);
}
.player input:focus-visible + .player__icon {
outline: 2px solid #1e1b4b;
outline-offset: 4px;
}
/* The visible label changes with the state, so the name is never
conveyed by shape alone. */
.player__label::before { content: "Play"; }
.player input:checked ~ .player__label::before { content: "Pause"; }
@media (prefers-reduced-motion: reduce) {
.player__icon { transition: none; }
}
</style>
</head>
<body>
<label class="player">
<input type="checkbox" aria-label="Playing">
<span class="player__icon" aria-hidden="true"></span>
<span class="player__label" aria-hidden="true"></span>
</label>
</body>
</html>
The pause outline is the part to study. A polygon is a single closed path, so two separate bars have to be drawn as one outline that visits both: down the left bar, along the bottom to the right bar, up and round it, and back along the bottom to the start. The two runs along the bottom edge lie on top of each other in opposite directions, so they enclose no area and the gap between the bars stays empty under the default nonzero fill rule. The play state uses the same trick in a different place: points two to five run down a zero-width slit in the middle of the triangle and back up. During the morph the left bar widens into the left half of the triangle, the right bar narrows into its tip, and the slit and the bottom run shrink to nothing — every point has a short, direct path, which is what keeps the middle frames clean.
The checkbox's aria-label="Playing" combined with its checked state gives screen readers "Playing, checkbox, checked" or "not checked". In production, a <button> with aria-pressed toggled by script is the more conventional control; the CSS-only checkbox is shown here because the morph itself needs no script.
The key technique: design the in-between frames
A morph is judged by its middle, not its ends. Because each point moves in a straight line at the same eased progress, the halfway frame is simply the average of the two point lists. Sketching that average before building the animation catches most problems.
Three habits make midpoints reliable:
- Write coordinates in percentages so the morph scales with the element and you can reason about positions on a 0–100 grid.
- Keep points convex where possible. Shapes whose vertices all bulge outward rarely self-intersect mid-morph. Concave shapes, like stars, need more care with order.
- Use an easing curve with some acceleration at both ends, such as
cubic-bezier(0.65, 0, 0.35, 1). Morphs look mechanical under linear timing and rushed under a strong ease-out, because the interesting middle frames fly past.
For a star, list outer and inner points alternately — outer, inner, outer, inner — and pad the other shape to the same alternating structure. A square morphing into a five-pointed star then needs ten points, with its padding placed so that "inner" points start on the square's edges near their final positions.
Variation: a disclosure chevron that flips
Not every morph needs extra points. A thick chevron that flips from pointing down to pointing up is a six-point polygon in both states, and mirroring the points vertically gives a morph whose middle frame collapses to a flat line — a quick, convincing flip without any rotation.
.chevron {
width: 1.25rem;
height: 1.25rem;
background: currentColor;
/* A thick V pointing down: outer edge 1-2-3, inner edge 4-5-6. */
clip-path: polygon(10% 30%, 50% 70%, 90% 30%, 90% 48%, 50% 88%, 10% 48%);
transition: clip-path 0.25s cubic-bezier(0.65, 0, 0.35, 1);
}
/* Pointing up: every point mirrored top to bottom (y becomes 100% - y).
Each point moves straight up or down, so edges never cross; halfway
through, all six points sit on the same line and the shape is flat. */
[aria-expanded="true"] > .chevron {
clip-path: polygon(10% 70%, 50% 30%, 90% 70%, 90% 52%, 50% 12%, 10% 52%);
}
@media (prefers-reduced-motion: reduce) {
.chevron { transition: none; }
}
The chevron sits inside a disclosure button whose aria-expanded attribute carries the real state, and the shape follows the attribute, so the visual and accessible states cannot disagree. Because each point moves along a single axis, this morph is also the easiest kind to verify: sketch the halfway frame and it is a straight horizontal line, with nothing to twist. The same mirroring idea gives sort-direction arrows and expand/collapse carets. When a rotation would do the job just as well, transform: rotate() is cheaper to animate than clip-path; Smooth Hover Effects Without JavaScript covers the transform-based approach.
Browser support
Animating clip-path: polygon() between polygons with equal point counts is supported in current versions of Chrome, Edge, Firefox and Safari. In an engine that cannot interpolate a given pair — for example, mismatched counts — the shape switches at the end of the transition rather than failing, so the state change is still visible. prefers-reduced-motion is supported in Chrome 74+, Edge 79+, Firefox 63+ and Safari 10.1+; under reduced motion the icon switches shape instantly.
FAQ
Why does my polygon morph jump instead of animating?
The two polygons have different numbers of points. polygon() only interpolates when both states list exactly the same number of vertices. Add duplicate points to the simpler shape until the counts match, placing them where they will spread out naturally.
Why does my morph twist or cross over itself halfway through? The points are listed in different orders or start from different corners. Each point travels in a straight line to the point at the same index, so if point one is the top of one shape and the left of the other, edges cross mid-animation. Start both lists at the same position and go round in the same direction.
Can clip-path morph between curved shapes?
Not with polygon(), which only draws straight edges. circle() and ellipse() morph among themselves, and the shape() and path() functions can describe curves, but path() only interpolates when both paths have identical command structures. For most UI morphs, a polygon with enough points is simpler.
Should a morphing icon still have a text label?
Yes. A shape change such as play becoming pause conveys state visually, but screen readers need the state in text. Keep an accessible name that updates with the state, for example through a label that changes with :checked, or aria-pressed on a button.
Related
- Clip-Path & Mask Animations — the parent guide.
- Clip-Path Reveal Animations — polygon interpolation used for reveals.
- CSS-Only Toggle Switches and Checkboxes — the checkbox state pattern behind the toggle.
- Container Query Hover Affordances — scaling icon motion to its container.
Related articles
More pages in the same section.