CSS triangle with clip-path
clip-path cuts an element to a shape: only the part inside is painted and receives clicks. With polygon() you list the corners of the shape as pairs of coordinates measured from the top-left of the box, in percentages or lengths. A triangle needs three corners: the middle of the top edge (50% 0), the bottom-right corner (100% 100%) and the bottom-left corner (0 100%). The generator opens on the triangle: drag the handles to change the shape, or choose one of the others.
A real result
clip-path: polygon(50% 0, 100% 100%, 0 100%);As a Tailwind arbitrary property:
[clip-path:polygon(50%_0,_100%_100%,_0_100%)]<div class="triangle" style="width: 120px; height: 104px; background: #ffb224"></div>The 12 ready-made shapes
Click a shape in the generator to load it. Their polygons, as the generator writes them:
| Shape | Points | polygon() |
|---|---|---|
| triangle | 3 | polygon(50% 0, 100% 100%, 0 100%) |
| trapezoid | 4 | polygon(20% 0, 80% 0, 100% 100%, 0 100%) |
| parallelogram | 4 | polygon(25% 0, 100% 0, 75% 100%, 0 100%) |
| rhombus | 4 | polygon(50% 0, 100% 50%, 50% 100%, 0 50%) |
| pentagon | 5 | polygon(50% 0, 97.55% 34.55%, 79.39% 90.45%, 20.61% 90.45%, 2.45% 34.55%) |
| hexagon | 6 | polygon(100% 50%, 75% 93.3%, 25% 93.3%, 0 50%, 25% 6.7%, 75% 6.7%) |
| octagon | 8 | polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%) |
| star | 10 | polygon(50% 0, 61.76% 33.82%, 97.55% 34.55%, 69.02% 56.18%, 79.39% 90.45%, 50% 70%, 20.61% 90.45%, 30.98% 56.18%, 2.45% 34.55%, 38.24% 33.82%) |
| cross | 12 | polygon(35% 0, 65% 0, 65% 35%, 100% 35%, 100% 65%, 65% 65%, 65% 100%, 35% 100%, 35% 65%, 0 65%, 0 35%, 35% 35%) |
| arrow | 7 | polygon(0 25%, 60% 25%, 60% 0, 100% 50%, 60% 100%, 60% 75%, 0 75%) |
| chevron | 6 | polygon(0 0, 70% 0, 100% 50%, 70% 100%, 0 100%, 30% 50%) |
| message | 7 | polygon(0 0, 100% 0, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0 75%) |
What else it cuts
- Borders and shadows: they are outside the clipped area, so a triangle made with clip-path has no border and no box-shadow. Use filter: drop-shadow() on a parent for a shadow that follows the shape.
- Clicks and hover: the corners that are cut away do not respond, which is useful for diagonal buttons and a nuisance if you expected the full box.
- Children: everything inside, text and images too, is cut by the same shape.
Common mistakes
- Animating between two polygons with different numbers of points: the browser cannot interpolate them and the shape jumps. Keep the same count.
- Using a triangle for an arrow of a tooltip that needs a border: build the arrow with two nested triangles, or use an SVG.
- Forgetting that percentages follow the box: a triangle in a wide box is not equilateral. For a regular triangle set a width and a height of about 0.866 times the width.
How to use the generator
- The triangle is loaded in polygon mode; drag a handle (or use the arrow keys, 1%, Shift 10%) to move a corner.
- Switch to circle, ellipse or inset for the other clip-path functions.
- Copy the CSS or the Tailwind class.
Frequently asked questions
How do I make a CSS triangle?
Give a box a size and a background color, then clip-path: polygon(50% 0, 100% 100%, 0 100%). Another way is the old border trick with a zero-size box, which cannot hold content.
How do I flip the triangle to point down?
Use polygon(0 0, 100% 0, 50% 100%). Drag the handles in the generator and it writes the new points.
Does clip-path work in all browsers?
Basic shapes (polygon, circle, ellipse, inset) work in all current browsers without a prefix.