clip-path shape morphing

clip-path 도형 모핑

clip-path's four basic shape functions — circle(), ellipse(), polygon(), inset() — cut an element down to that region, and modern browsers can smoothly morph between different ones.

Also known as: circle()ellipse()polygon()inset()
···
html
<div class="wrap"><div class="photo" id="photo"></div><div class="label" id="l">clip-path: circle()</div></div>
css
.wrap{position:relative;display:grid;place-items:center;gap:16px}
.photo{width:min(70vmin,280px);aspect-ratio:4/3;transition:clip-path .8s cubic-bezier(.4,0,.2,1);
  background:linear-gradient(135deg,#ff5c8a,#5b5bf7 55%,#18c29c)}
.label{font:600 12px/1.4 monospace;color:var(--muted)}
js
const SHAPES = [
  ['circle(38% at 50% 50%)', 'circle()'],
  ['ellipse(45% 30% at 50% 50%)', 'ellipse()'],
  ['polygon(50% 0%,100% 38%,82% 100%,18% 100%,0% 38%)', 'polygon()'],
  ['inset(10% 15% 10% 15% round 18px)', 'inset()'],
];
const photo = document.getElementById('photo');
const l = document.getElementById('l');
let i = 0;
function apply(){ const [css, label] = SHAPES[i]; photo.style.clipPath = css; l.textContent = 'clip-path: ' + label; i = (i + 1) % SHAPES.length; }
apply();
setInterval(apply, 1600);

clip-path doesn't actually crop or resize the element — it just hides whatever falls outside the shape you give it. The four most-used functions are circle(radius at centre), ellipse(rx ry at centre), polygon(point list), and inset(top right bottom left [round radius]).

Transitions used to only work between the same function (polygon to polygon, etc.), but modern browsers convert every basic-shape function into a shared internal path representation before comparing them, so a transition straight from circle() to polygon() now morphs smoothly. The demo shows exactly that — it just cycles through all four functions, and the browser interpolates between them on its own.

Like filter, transform, and opacity < 1, clip-path also creates a new stacking context (and in Chromium, its own compositing layer), so it adds up across many animated elements. It's also tempting to assume the hidden region blocks clicks by default — but that hit-testing behaviour isn't spec-guaranteed, so if clicks must be limited to the visible shape, add an SVG hit region or your own point-in-polygon check rather than relying on clip-path alone.

When to use

For image reveals, modal openings, or a floating action button that changes shape. If clicks must be confined to the visible shape, add your own hit-testing.