π What Is clip-path?
The clip-path property allows you to visually clip (cut) an element into a specific shape β such as a circle, polygon, star, or any custom path.
It hides everything outside the defined shape, creating powerful UI design possibilities like diagonal sections, avatars, creative buttons, loaders, and hero banners. π¨β¨
π§© Basic Syntax
Syntax
clip-path: <basic-shape> | path() | url(#svgClipPath);
clip-path: circle(50%);
clip-path: inset(10px);
clip-path: polygon(...);
clip-path: path('M0 0 L100 0 L50 100 Z');β Supports CSS shapes
β Supports SVG paths
β Supports SVG clipPath via URL
π― Types of clip-path Shapes
| Shape Type | Example | Usage |
|---|---|---|
| circle() | circle(50%) | Round avatars, badges |
| ellipse() | ellipse(50% 30%) | Smooth curved shapes |
| inset() | inset(10px) | Rectangular cropping |
| polygon() | polygon(0 0, 100% 0, 50% 100%) | Triangles, diamonds, custom shapes |
| path() | path("M0 0 L100 0 Z") | Complex freeform SVG shapes |
| url(#clipPath) | References SVG clipPath | Full SVG clipping capabilities |
π§ͺ Example: Circle Clip
Circle avatar
.avatar {
clip-path: circle(50%);
}β Perfect for profile pictures or round buttons.
π§ͺ Example: Ellipse Clip
ellipse
.banner {
clip-path: ellipse(60% 40% at center);
}β Creates smooth, curved hero sections.
π§ͺ Example: Polygon Clip (Triangle)
triangle
.triangle {
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}β Often used for ribbons, badges, and design accents.
π§ͺ Example: Diagonal Section
Diagonal section
.diagonal {
clip-path: polygon(0 0, 100% 10%, 100% 100%, 0 90%);
}β A modern design trend for sections and hero headers.
π§ͺ Example: Using inset()
inset crop
.crop {
clip-path: inset(20px 40px 20px 40px);
}β Clips equally from each side β useful for cropping edges.
π₯ Advanced: Using path() for Complex Shapes
path() example
.blob {
clip-path: path("M10,80 Q95,10 180,80 T350,80");
}β Enables organic shapes, blobs, waves
β Works similarly to SVG path drawing
π§ͺ SVG clipPath Usage
SVG clipPath example
<svg width="0" height="0">
<clipPath id="clipStar" clipPathUnits="objectBoundingBox">
<polygon points="0.5 0, 0.6 0.35, 1 0.35, 0.7 0.57, 0.82 1, 0.5 0.72, 0.18 1, 0.3 0.57, 0 0.35, 0.4 0.35"/>
</clipPath>
</svg>
<div class="star"></div>
.star {
clip-path: url(#clipStar);
}β Gives ultimate flexibility with vector shapes.
π¨ Clip Path + Hover Animation
Animated clip
.btn {
clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
transition: clip-path 0.4s ease;
}
.btn:hover {
clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%);
}β Smooth animated transitions between shapes.
π Clip Path + Scroll Animation
Scroll reveal
@keyframes reveal {
from { clip-path: inset(100% 0 0 0); }
to { clip-path: inset(0); }
}
.reveal {
animation: reveal 1s ease forwards;
}β Creates a clean βwipe-inβ effect.
π οΈ Tools to Generate Clip Paths
β οΈ Browser Support
- β Chrome
- β Edge
- β Safari
- β οΈ Firefox fully supports clip-path shapes; SVG paths require prefixes
Note
π Debugging Tips
- Check if your polygon points are valid (0β100% or px)
- Use clip-path: inset(0) to test masking reset
- If using path() and nothing appears β ensure browser supports it
- Add a visible background to see clipping clearly