βœ‚οΈ Mastering clip-path in CSS

πŸ“Œ 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. 🎨✨

>>β€œclip-path is like a cookie cutter for your elements β€” cut any shape you imagine.”

🧩 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 TypeExampleUsage
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 clipPathFull 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

For SVG paths in clip-path on HTML elements, Safari may require -webkit-clip-path.

πŸ” 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

πŸ”— Helpful Resources

>>β€œWith clip-path, every element becomes a shape-shifting canvas β€” cut, curve, and craft freely.” βœ¨βœ‚οΈ