The CSS clip-path property is a powerful tool that allows you to define which parts of an element are visible by “clipping” it to a specific shape or path. It essentially creates a mask — only the area inside the defined path remains visible, while everything outside is hidden. With clip-path, you can create complex geometric shapes, animations, and unique layout effects that go far beyond the typical rectangular boundaries of HTML elements.
By default, every HTML element is rendered as a rectangle. The clip-path property changes that by defining a visible area using a geometric shape or an SVG path. This can be done using basic shapes like circle(), ellipse(), polygon(), and inset(), or with custom path() values for more complex designs.
Here’s the basic syntax:
.element {
clip-path: shape(arguments);
}
You can also use clip-path with an external SVG reference:
.element {
clip-path: url(#myClipPath);
}
clip-path: circle(50% at 50% 50%);
clip-path: ellipse(60% 40% at 50% 50%);
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
clip-path: inset(10% 20% 10% 20% round 20px);
Each shape can use percentages, pixels, or other length units to define its size and position, and they can be centered anywhere within the element using the at keyword.
The polygon() function is the most flexible and commonly used form of clip-path. It allows you to define a shape by specifying multiple points that form a closed polygon. Each point is defined by X and Y coordinates.
.element {
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
}
You can create triangles, hexagons, arrows, or even custom shapes like waves by manipulating the coordinates. Online generators often provide visual editors where you can click to add or move points and instantly see how the clipping shape changes.
One of the most exciting uses of clip-path is in animations. Since the clipping area can change over time, you can create dynamic transitions between shapes or reveal/hide elements in creative ways.
@keyframes reveal {
from {
clip-path: circle(0% at 50% 50%);
}
to {
clip-path: circle(75% at 50% 50%);
}
}
.image {
animation: reveal 2s ease-in-out forwards;
}
This animation starts with a small circular mask in the center and expands outward, revealing the entire image as the animation progresses.
For ultimate flexibility, you can use the path() function, which follows the same syntax as SVG path data. This enables you to clip elements to any vector shape imaginable.
.element {
clip-path: path("M0,100 Q50,0 100,100 Z");
}
This example creates a curved “wave-like” shape at the bottom of an element using a quadratic Bézier curve (Q command).
clip-path with gradients or SVG to create flowing page transitions.
The clip-path property is supported by all major browsers, including Chrome, Firefox, Edge, and Safari. However, older browsers may require vendor prefixes or fallback solutions. For SVG-based clipping, make sure your <clipPath> elements have the proper clipPathUnits set to objectBoundingBox for percentage-based control.
clip-path with transform and filter for stunning visual effects.
The clip-path property gives designers and developers the freedom to break out of the box-shaped layout paradigm of the web. With its ability to define complex, animatable shapes using both simple geometry and vector paths, clip-path opens the door to highly creative, modern web designs. Whether you’re building unique section dividers, masking images, or animating shape transitions, mastering clip-path is an essential skill for today’s front-end developer.