Clip Path — CSS

clip-path cuts what you see of an element into another shape, and the part outside the shape is not shown. polygon() builds any shape from corner points. Each…

Every element on a web page is a box. clip-path cuts what you see of that box into another shape: a triangle, a diamond, a circle. The part of the box outside the shape is not shown. Think of paper cut along a pattern: the box is the paper, the shape is the pattern, and the paper outside the pattern is thrown away.

Cut a triangle with polygon()

This rule cuts a box into a triangle:

.triangle {
  width: 200px;
  height: 200px;
  background: coral;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

The result is a coral triangle with its tip at the top middle. A few other points for reference: 0% 0% is the top left corner, 100% 0% is the top right corner, and 50% 50% is the middle of the box.

A diamond: four points in the middle of the sides

A diamond has four corners. Each corner is in the middle of one side of the box. Write the four points in order around the box, clockwise:

.diamond {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

The order is: top middle 50% 0%, right middle 100% 50%, bottom middle 50% 100%, then left middle 0% 50%. The order matters, because the browser joins the points in the order you write them. If the points jump from place to place, the lines cross each other.

Circles, ellipses and inset()

For round shapes and for boxes with their edges cut off, there are ready-made functions:

Only the look is cut

An element that has been cut still keeps the space of its full box, so the other elements don't move. But clicks and hovers follow the cut shape: the part that was cut away can't be clicked or hovered. So if a box is cut into a circle, a click on a corner that is gone does not reach the box.

⚠️ When the cut is not what you planned

TL;DR: clip-path cuts what you see of an element into another shape, and the part outside the shape is not shown. polygon() builds any shape from corner points. Each point is written x y (percent from the left and from the top), points are separated by commas, and you write them in order around the shape. circle() makes a circle, ellipse() makes an oval, and inset() cuts a box inward from its edges. The element keeps the space of its full box, but the part that was cut away can't be clicked.

⚡ Cut a triangle

Write:

.triangle {
  width: 200px;
  height: 200px;
  background: coral;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
Guess first: the code above cuts a box into a triangle, from three points separated by commas. If you remove the commas, polygon(50% 0% 100% 100% 0% 100%), what shape does the box get?

The box stays whole. Without commas the value is not valid, so the browser ignores the whole clip-path declaration.

Meaning: clip-path cuts what you see of an element into another shape. polygon() joins corner points into one shape. Each point is written x y as percentages: x from the left, y from the top. Points are separated by commas. 50% 0% is the top middle.

⚡ Ready-made round shapes

Write:

clip-path: circle(50%);

Meaning: circle() makes a circle, and the number is the radius (the distance from the centre to the edge of the circle). ellipse() makes an oval, and inset() cuts inward from the edges of the box.

⚡ Only the look is cut

Guess first: a box is cut into a circle. Can you still click a corner that is gone?

No. The part that was cut away can't be clicked or hovered.

Meaning: The cut element still keeps the space of its full box, so the elements around it don't move.

What you will learn