CSS clip-path
Create stunning custom shapes and creative layouts with CSS clip-path. Master geometric shapes, complex polygons, and smooth animations.
What is clip-path in CSS?
clip-path cuts an element into a shape and hides everything outside it. Use basic shapes like circle(50%), ellipse(), inset() and polygon(), or reference an SVG <clipPath>. It's commonly used for slanted section edges, hexagon avatars and reveal animations.
.avatar { clip-path: circle(50%); }
.slanted { clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%); }
.reveal { clip-path: inset(0 100% 0 0); transition: clip-path .6s; }
.reveal.show { clip-path: inset(0 0 0 0); }Interactive clip-path Demo
Code Editor
<div class="row">
<div class="shape circle">circle</div>
<div class="shape triangle">triangle</div>
<div class="shape slant">slant</div>
<div class="shape hex">hexagon</div>
</div>Preview
Basic Clip-Path Shapes
Simple Geometric Shapes
/* Circle */ .circle {
clip-path: circle(50% at center);
/* circle(radius at position) */
}
/* Ellipse */ .ellipse {
clip-path: ellipse(60% 40% at center);
/* ellipse(rx ry at position) */
}
/* Inset rectangle */ .inset {
clip-path: inset(10px 20px 30px 40px);
/* inset(top right bottom left) */
}
/* Rounded inset */ .rounded-inset {
clip-path: inset(10px round 15px);
/* Add rounded corners */
}
/* Dynamic circle */ .dynamic-circle {
clip-path: circle(40% at 30% 70%);
/* Off-center circle */
}Start with basic shapes to understand clip-path syntax and positioning.
Circle Variations
/* Perfect circle */ .perfect-circle {
clip-path: circle(50%);
}
/* Small circle */ .small-circle {
clip-path: circle(30%);
}
/* Off-center circle */ .off-center {
clip-path: circle(40% at 80% 20%);
}
/* Responsive circle */ .responsive-circle {
clip-path: circle(clamp(20%, 10vw, 50%));
}Experiment with different circle sizes and positions
Inset Techniques
/* Equal inset */ .equal-inset {
clip-path: inset(20px);
}
/* Asymmetric inset */ .asymmetric {
clip-path: inset(10px 30px 20px 5px);
}
/* Rounded corners */ .rounded {
clip-path: inset(15px round 20px);
}
/* Different corner radii */ .mixed-corners {
clip-path: inset(10px round 5px 15px);
}Create precise rectangular cuts with optional rounding
Polygon Shapes
Creating Custom Polygons
/* Triangle */ .triangle {
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
/* Diamond */ .diamond {
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
/* Pentagon */ .pentagon {
clip-path: polygon(
50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%
);
}
/* Hexagon */ .hexagon {
clip-path: polygon(
25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%
);
}
/* Arrow */ .arrow {
clip-path: polygon(
0% 20%, 60% 20%, 60% 0%, 100% 50%, 60% 100%, 60% 80%, 0% 80%
);
}Use polygon() to create any shape by defining coordinate points.
Complex Polygons
/* Star shape */ .star {
clip-path: polygon(
50% 0%, 61% 35%, 98% 35%, 68% 57%,
79% 91%, 50% 70%, 21% 91%, 32% 57%,
2% 35%, 39% 35%
);
}
/* Speech bubble */ .speech-bubble {
clip-path: polygon(
0% 0%, 100% 0%, 100% 75%, 75% 75%,
75% 100%, 50% 75%, 0% 75%
);
}
/* Ribbon */ .ribbon {
clip-path: polygon(
0% 0%, 90% 0%, 100% 50%, 90% 100%,
0% 100%, 10% 50%
);
}Create intricate shapes for unique design elements
Coordinate System
/* Understanding coordinates */ /* Top-left: 0% 0% */
/* Top-right: 100% 0% */
/* Bottom-right: 100% 100% */
/* Bottom-left: 0% 100% */
/* Center: 50% 50% */
/* Right triangle */ .right-triangle {
clip-path: polygon(
0% 0%, /* top-left */
100% 100%, /* bottom-right */
0% 100% /* bottom-left */
);
}
/* Parallelogram */ .parallelogram {
clip-path: polygon(
25% 0%, 100% 0%, 75% 100%, 0% 100%
);
}Master the coordinate system for precise shape control
Animations & Transitions
Morphing Animations
/* Basic transition */ .morphing-shape {
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
transition: clip-path 0.5s ease;
}
.morphing-shape:hover {
clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
}
/* Keyframe animation */ @keyframes shape-morph {
0% {
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
50% {
clip-path: polygon(50% 20%, 80% 50%, 50% 80%, 20% 50%);
}
100% {
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
}
.animated-diamond {
animation: shape-morph 3s ease-in-out infinite;
}Create smooth transitions between different clip-path shapes.
Reveal Effects
/* Left to right reveal */ @keyframes reveal-lr {
from {
clip-path: inset(0 100% 0 0);
}
to {
clip-path: inset(0 0% 0 0);
}
}
/* Circular reveal */ @keyframes reveal-circle {
from {
clip-path: circle(0% at center);
}
to {
clip-path: circle(100% at center);
}
}
/* Polygon reveal */ @keyframes reveal-polygon {
from {
clip-path: polygon(50% 50%, 50% 50%, 50% 50%);
}
to {
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
}
}Progressive disclosure with animated clip-paths
Performance Tips
/* ✅ Good - same number of points */ .good-transition {
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
transition: clip-path 0.3s ease;
}
.good-transition:hover {
clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
}
/* ⚠️ Avoid - different number of points */ .poor-transition {
clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}
.poor-transition:hover {
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
/* Use will-change for better performance */ .optimized {
will-change: clip-path;
}Ensure smooth animations with consistent point counts
Practical Applications & Best Practices
Best Practices
- • Use CSS variables for dynamic shapes
- • Maintain consistent polygon point counts
- • Add fallbacks for older browsers
- • Test with actual content and images
- • Consider accessibility implications
- • Use clip-path generators for complex shapes
Common Use Cases
- • Hero section creative layouts
- • Image masking and framing
- • Button and badge designs
- • Loading and progress indicators
- • Decorative section dividers
- • Interactive reveal animations
CSS clip-path — step by step
Basic Shapes
Use clip-path: circle(50%), ellipse(), inset(), or polygon() to clip elements to geometric shapes — anything outside the path is invisible.
🎯 Quick Check
What does clip-path do to content outside the defined shape?
CSS clip-path: summary
Key points
- Clipped-away areas don't receive clicks or hovers.
- Two shapes of the same type with the same number of points can be animated between.
clip-pathdoesn't add shadows; wrap the element and putfilter: drop-shadow()on the wrapper.
Frequently asked questions
›How do I make a triangle with clip-path?
Use clip-path: polygon(50% 0, 100% 100%, 0 100%); on a square element.
›What is the difference between clip-path and mask?
clip-path uses a hard-edged geometric shape. mask uses an image or gradient, so it can have soft, partially transparent edges.