CSS clip-path: shapes, polygons and examples

How to crop an element to a circle, ellipse, inset rectangle or polygon with clip-path, with ready-made shape values.

Updated

The clip-path property crops an element to a shape. Everything inside the shape stays visible, and everything outside is hidden and cannot be clicked. The element keeps its original size in the layout. You define the shape with one of the basic shape functions: inset(), circle(), ellipse() or polygon().

.avatar {
  clip-path: circle(50%);
}

The shape functions

inset() cuts a rectangle in from each edge. Values go top, right, bottom, left, as with margin. An optional round adds corner radii.

clip-path: inset(10% 20% 10% 20% round 12px);

circle() takes a radius and an optional center.

clip-path: circle(40% at 50% 50%);

ellipse() takes a horizontal radius and a vertical radius, plus an optional center.

clip-path: ellipse(50% 35% at 50% 50%);

polygon() takes a list of x and y points, joined in order by straight lines.

clip-path: polygon(50% 0%, 100% 100%, 0% 100%);

How the coordinates work

Each point is an x value and then a y value, measured from the top left corner of the element. 0% 0% is the top left and 100% 100% is the bottom right. Percentages make the shape scale with the element. You can also use lengths such as px or rem, and mix the two with calc().

Shapes to copy

Shape Value
Triangle polygon(50% 0%, 0% 100%, 100% 100%)
Rhombus polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)
Parallelogram polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%)
Trapezoid polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%)
Hexagon polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%)
Right-pointing chevron polygon(75% 0%, 100% 50%, 75% 100%, 0% 100%, 25% 50%, 0% 0%)
Message bubble polygon(0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75%)

Animating

clip-path can be transitioned and animated when the start and end shapes use the same function and, for polygons, the same number of points.

.reveal {
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.4s ease;
}
.reveal.is-visible {
  clip-path: inset(0 0 0 0);
}

This wipes the element in from the left. To morph between polygons with different numbers of points, add duplicate points to the simpler shape until the counts match.

Things that catch people out

  • Shadows and outlines are clipped too. A box-shadow on a clipped element is cut away. Put filter: drop-shadow() on a parent element instead; see box-shadow.
  • Clipped areas do not respond to the pointer. Hover and click work only inside the shape.
  • Layout does not change. Other elements still flow around the original rectangle. To wrap text around a shape, use shape-outside on a floated element.
  • Focus rings can vanish. An outline on a clipped button may be cut off. Draw the focus style inside the shape or on a wrapper.

Beyond basic shapes

clip-path also accepts path() with SVG path data, which gives you curves, and url(#id) to reference an SVG <clipPath> element. Path coordinates are in pixels, so they do not scale with the element the way percentages do.

Related: gradient syntax.