Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

CSS clip path generator

This CSS clip path generator builds a clip-path: polygon() line for a hexagon, triangle, star, chevron, cross and more. Change the numbers, watch the preview and copy the CSS.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Sides or points and Rotation apply to the regular polygon and the star. Amount sets the star's inner radius, the slant of the parallelogram, trapezoid and chevron, or the arm inset of the cross.

Hexagon
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  • 6 points
  • Percent units: scales with the box
  • Fills the whole box
Points of the shape
PointXY
150%0%
2100%25%
3100%75%
450%100%
50%75%
60%25%

How to use the CSS Clip Path Generator

  1. Choose a Shape. The default is a hexagon.
  2. Set Sides or points and Rotation (degrees) for a regular polygon or a star, and Amount (percent) for a star, parallelogram, trapezoid, chevron or cross.
  3. Check the shape in the preview and the numbers in the Points of the shape table.
  4. Press Copy CSS and paste the line into the rule of the element you want to cut.

How does clip-path: polygon() work?

The polygon() function takes a list of points separated by commas, and each point is an x value and a y value. With percentages, 0% 0% is the top left corner of the element and 100% 100% is the bottom right. The browser joins the points in the order written and closes the shape back to the first point, and everything outside the shape is hidden. MDN states that a polygon needs at least three points. The default hexagon of this tool is clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);, six points for six corners.

Percentages make the shape follow the element. A box that is 300 px wide and 150 px high gives a stretched hexagon, and on a box about 87 px wide and 100 px high the same line gives a regular hexagon, since the tool stretches every polygon to touch all four edges. Each coordinate can also be a length such as 20px, which the tool does not produce, but you can edit the copied line by hand.

MDN also lists an optional fill rule, nonzero by default or evenodd, written before the first point. It only changes the result when lines cross each other, as in a star drawn with overlapping lines. The shapes here never cross, so the line is left without one.

How are regular polygons and stars calculated?

The tool places the points on a circle that fits the box, starting at the top and moving clockwise. For n sides, point k sits at the angle −90° + rotation + 360° × k ÷ n, with the centre at 50% 50% and a radius of 50%. It then stretches the result so the points touch all four edges of the box. That is why a triangle reads polygon(50% 0%, 100% 100%, 0% 100%), with the bottom corners on the corners of the box, instead of leaving a quarter of the box empty at the bottom.

Rotation turns the starting angle. A four-sided shape with no rotation is a diamond, polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%), and turning it 45 degrees gives the square polygon(100% 0%, 100% 100%, 0% 100%, 0% 0%).

A star has twice as many points as it has tips: 10 for a five-tip star. Even points sit on the outer radius and odd points sit on the inner radius, which is the Amount you type as a percent of the outer one. With an amount of 40 the five-tip star becomes polygon(50% 0%, 62.36% 37.39%, 100% 38.2%, 70% 62.11%, 80.9% 100%, 50% 77.39%, 19.1% 100%, 30% 62.11%, 0% 38.2%, 37.64% 37.39%). A low amount gives thin spikes and a high one gives a fat, almost round star.

Common shapes and the lines they give

The table lists the regular polygons with default settings. Each line is what the tool outputs when you pick the shape and the number of sides.

Regular polygons as clip-path lines
ShapeSidesCSS value
Triangle3 sidespolygon(50% 0%, 100% 100%, 0% 100%)
Diamond4 sidespolygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)
Pentagon5 sidespolygon(50% 0%, 100% 38.2%, 80.9% 100%, 19.1% 100%, 0% 38.2%)
Hexagon6 sidespolygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%)
Octagon8 sidespolygon(50% 0%, 85.36% 14.64%, 100% 50%, 85.36% 85.36%, 50% 100%, 14.64% 85.36%, 0% 50%, 14.64% 14.64%)

The other shapes use the Amount box. A parallelogram with a slant of 20 is polygon(20% 0%, 100% 0%, 80% 100%, 0% 100%). A chevron with a depth of 25 is polygon(0% 0%, 75% 0%, 100% 50%, 75% 100%, 0% 100%, 25% 50%), which gives a 6 point arrow shape for breadcrumbs and step headers. A cross with an arm inset of 20 is polygon(20% 0%, 80% 0%, 80% 20%, 100% 20%, 100% 80%, 80% 80%, 80% 100%, 20% 100%, 20% 80%, 0% 80%, 0% 20%, 20% 20%), 12 points in all.

Using the copied line

Paste the line into the CSS rule of the element, such as an image, a card or a button, and the element is cut to the shape. MDN says the border box is the reference box when none is given, so the percentages are measured on the box including its border, and the border is cut along with everything else. For a shadow or outline that follows the shape, put the clipped element inside a wrapper and give the wrapper filter: drop-shadow(), which traces the cut edge.

For shadows on elements that are not clipped, use the box shadow generator. For layout around the shape see the CSS grid generator, and the px to rem converter turns pixel lengths into rem if you edit the line to use lengths. The SVG viewer helps when a shape needs curves, since polygon() only draws straight edges.

Use it with

Questions

How do I make a hexagon with CSS?

Set clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); on the element. The tool gives you this line by default, and you can change the rotation or the number of sides.

How do I make a triangle with clip-path?

Use clip-path: polygon(50% 0%, 100% 100%, 0% 100%);. Choose Regular polygon and set the sides to 3.

How many points does polygon() need?

At least three. The shape closes itself from the last point back to the first.

Can I use pixels instead of percentages?

Yes. polygon() accepts lengths and percentages. This tool writes percentages so the shape scales with the element, and you can swap values for lengths by hand.

What does the Amount box do?

It depends on the shape: the inner radius of a star, the slant of a parallelogram, trapezoid or chevron, or the inset of the corners of a cross. The hint under the form lists each one.

Is anything uploaded when I use the tool?

No. The shape is calculated in your browser and nothing you type is sent anywhere.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.