الأدوات · CSS · مولّد clip-path · الأدلة · Why Shape Elements With CSS clip-path Instead of Cropped Images
Why Shape Elements With CSS clip-path Instead of Cropped Images
When a design calls for a hexagon avatar, a hero section with a slanted bottom edge, or a badge shaped like a speech bubble, there are two ways to get it. You can bake the shape into the image itself, exporting a PNG with transparent corners for every photo, or you can keep the photo rectangular and let the browser cut it at render time. clip-path is the second way: one CSS declaration that hides everything outside a shape you describe. For most shaped UI it is the better choice, and the reasons are practical rather than fashionable.
What baking the shape into the file costs
A shaped PNG works, but every new photo needs the same trip through an image editor. A team page with twenty people means twenty exports, and a user-uploaded avatar cannot go through an editor at all. Transparent corners also push you toward PNG or WebP with alpha even when the photo itself would be smaller as a plain JPEG. And the shape is now frozen in the asset: if the designer later wants a pentagon instead of a hexagon, every file gets exported again.
With clip-path, the image stays an ordinary rectangle in whatever format suits it, and the shape lives in one place in the stylesheet. Changing the shape is a one-line edit. Because polygon() points are written as percentages of the element's box, the same rule fits a 48-pixel thumbnail and a full-width banner without any new coordinates.
What clip-path does not change
The cut is visual only. The element keeps its full rectangular box for layout, so neighbouring content does not flow into the area you clipped away. If you want text to wrap around a shape, that is a different property, shape-outside, and it only applies to floats.
Three side effects catch people the first time:
- Shadows and borders are clipped too. A
box-shadowsits outside the shape, so it disappears. Abordersurvives only where the shape's edge happens to run along the original box edge. The usual fix for the shadow isfilter: drop-shadow()on a wrapper element, which follows the clipped outline. - The clipped area stops taking clicks. Pointer events only land inside the visible shape. On a button or a card link, the corners you cut away are no longer clickable, which is usually what you want and occasionally a surprise.
- Clipped content is still in the page. Screen readers still read text that the shape hides, and it is still selectable. Clipping is not a way to hide content from anyone but sighted users.
Why it suits motion as well as static shapes
A shape defined in CSS can be transitioned. Two polygon() values with the same number of points interpolate point by point, so a card can morph from a rectangle into a chevron on hover with an ordinary transition. If the point counts differ, the browser has nothing to pair up and jumps straight to the end state instead of animating. That one rule shapes how you author polygons you intend to animate: keep the count equal, even if it means a rectangle defined with six points where four would do. Baked images cannot do any of this.
Where the hard part actually is
The syntax is not the problem. polygon(50% 0%, 0% 100%, 100% 100%) is a triangle, and anyone can read it. The problem is anything past a triangle: placing six, ten or twelve points by typing numbers, reloading, and squinting is slow, and it is easy to get one point in the wrong order and end up with an edge crossing the whole shape. That is the gap a visual editor closes.
Clip-path generator lets you start from a preset or a circle, ellipse or inset, drag the points on a live preview, and copy the CSS, all in your browser. The how-to guide walks through building a polygon step by step, and this one follows one real job, a hexagon profile photo, including the parts that go wrong.