The CSS Masking Module & The clip-path Property
The clip-path property, formalized in the W3C CSS Masking Module Level 1, creates a clipping region that demarcates which portions of an element are rendered to the screen. Everything inside the boundary of the closed path is visible; any pixel falling outside the boundary is discarded by the browser's rasterizer.
Historically, developers had to rely on the deprecated CSS 2.1 clip: rect(...) property (which only supported absolute-positioned rectangles) or bake destructive alpha cutouts directly into raster image files. Modern clip-path operates directly on live DOM nodes, images, video elements, and canvas containers using vector mathematics, providing non-destructive, responsive, and hardware-accelerated geometric cropping.
Clipping (1-Bit Binary) vs. Masking (8-Bit Alpha Grayscale)
While related, clipping and masking serve distinct technical functions:
clip-path(Clipping): A binary 1-bit stencil operation. Every screen coordinate is either 100% opaque or 100% transparent. Because it computes sharp vector boundaries without evaluating smooth alpha gradients, clipping is exceptionally fast and inexpensive for GPU rendering pipelines.mask-image(Masking): An 8-bit alpha or luminance channel operation that supports variable levels of transparency (such as feathered edges, smoke dissolves, and linear fade-outs).
Basic Shape Functions & Coordinate Geometry
The clip-path property accepts basic shape functions defined relative to the element's coordinate box:
1. Polygons (polygon(x1 y1, x2 y2, ...))
The polygon() function accepts a comma-separated list of coordinate pairs representing vertices. Pairs are plotted from the top-left origin (0% 0%), where the first value is the horizontal X-axis and the second value is the vertical Y-axis:
/* Diagonal chevron / arrow banner */
clip-path: polygon(0% 0%, 80% 0%, 100% 50%, 80% 100%, 0% 100%, 20% 50%);2. The Winding Rules: `nonzero` vs. `evenodd`
When plotting self-intersecting polygons (like a 5-pointed star or a donut shape with a hollow center cutout), how does the browser know whether an inner loop is "inside" or "outside"? You can specify an optional fill-rule keyword before the coordinates:
nonzero(default): Draws an imaginary ray from a point out to infinity and counts how many times path segments cross it clockwise vs. counter-clockwise. If the sum is non-zero, the area is filled.evenodd: Counts total ray-segment intersections. If the number of crossings is odd, the point is inside; if even, it is outside. This makes creating hollow cutouts and complex geometric lattices straightforward:clip-path: polygon(evenodd, 0% 0%, 100% 0%, 100% 100%, 0% 100%, 20% 20%, 80% 20%, 80% 80%, 20% 80%);
3. Circles & Ellipses (circle() & ellipse())
The circle() function creates a radial mask defined by a radius length or keyword (closest-side, farthest-side) and an anchor position:
/* Centered circular avatar */
clip-path: circle(50% at 50% 50%);
/* Off-center oval cutout */
clip-path: ellipse(40% 60% at 30% 50%);4. Inset Boxes (inset())
The inset() function crops inward from the outer edges using standard CSS 4-value margin shorthand (top, right, bottom, left) with an optionalround parameter for corner curvature:
/* Crop 20px inward on all sides with 12px rounded corners */
clip-path: inset(20px round 12px);5. SVG Paths (path())
Modern browsers support the path() function, allowing raw SVG path data strings (e.g., Bézier curves M... C... Z) to be declared directly in CSS without referencing an external SVG file:
clip-path: path('M 10,30 A 20,20 0 0,1 50,30 A 20,20 0 0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 Z');Geometry Reference Boxes (GeometryBox)
By default, coordinate percentages in clip-path are computed relative to the element's border-box. You can change this reference coordinate system by appending a geometry-box keyword:
| Reference Box | Target Context | Behavior & Coordinate Origin |
|---|---|---|
| border-box | HTML Elements (Default) | Includes content, padding, and border. Shapes scale to outer edge. |
| padding-box | HTML Elements | Excludes borders; clips strictly within the inner border boundary. |
| content-box | HTML Elements | Confines coordinates strictly to the inner content area inside padding. |
| view-box / fill-box | SVG Elements | Uses SVG viewport bounds or element bounding geometry. |
Hit-Testing, Pointer Events & Accessibility Hazards
Pointer Event Hit-Testing Follows the Vector Geometry
One of the most remarkable features of clip-path is its native integration with the browser's interactive hit-testing pipeline. In standard CSS (e.g., using opacity or overflow), elements remain rectangular bounding boxes that swallow mouse clicks even in transparent regions.
With clip-path, mouse hovers, clicks, and tap events are strictly restricted to the visible interior of the path. Clicks occurring in the discarded regions pass completely through to underlying elements as if the element did not exist at those coordinates.
Accessibility Hazard: Visual Clipping vs. Screen Readers
Clipping an element with clip-path affects only its visual presentation on the rendering layer. It does not remove content from the accessibility tree.
If text, buttons, or form controls are clipped out of view using clip-path: circle(0%), screen readers and keyboard navigation (Tab key traversing) can still interact with them. If your intention is to truly hide an element from all users, use display: none, visibility: hidden, or the HTML hidden attribute. If you intentionally want a visually hidden "skip to content" link that remains screen-reader accessible,clip-path: inset(50%) is the modern, recommended replacement for legacy offscreen text hacks (like left: -9999px).
Critical Gotchas & Production Workarounds
1. The Disappearing `box-shadow` Trap
A frequent trap for engineers is adding a box-shadow to a clipped element and wondering why the shadow never appears. Because clip-path clips all pixels rendered outside the path boundary—including borders and shadows—the outer box shadow is instantly trimmed away!
The Solution: Wrap the clipped element in a parent container and apply CSS filter: drop-shadow(...) on that parent. Unlikebox-shadow, drop-shadow() conforms to the alpha contour of child geometry:
/* Wrapper element casts shadow along the polygon contour */
.card-wrapper {
filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.3));
}
/* Clipped child element */
.card-inner {
clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%);
}2. Shape Morphing Parity Rule
You can animate between two different polygon() declarations using standard CSS transitions or @keyframes, but browser animation engines enforce a strict requirement: both polygons must contain the exact same number of vertices.
If you attempt to transition from a triangle (3 vertices) to a rectangle (4 vertices), the animation fails and snaps instantaneously. To morph between them smoothly, define "dummy" or duplicate vertices in the simpler shape:
/* Morphing a triangle into a rectangle (4 vertices each) */
.morph-shape {
/* Triangle with vertex 3 duplicated on top of vertex 2 */
clip-path: polygon(50% 0%, 100% 100%, 100% 100%, 0% 100%);
transition: clip-path 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.morph-shape:hover {
/* Expands cleanly into a 4-point rectangle */
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
}Practical Real-World Use Cases
- Create an angled hero section: Generate a polygon clip-path to give a rectangular landing-page banner a clean diagonal bottom edge.
- Build geometric image frames: Mask square avatars or product photos into hexagons, diamonds, or custom polygons using pure CSS.
- Design slanted section dividers: Create angled transitions between full-width page sections without exporting custom SVG background assets.
- Prototype decorative UI shapes: Adjust polygon vertices visually in the browser before copying the clip-path declaration into a stylesheet.
- Highlight promotional callout tiles: Give featured pricing cards or announcement banners a distinct notched corner silhouette.
Zero Server Upload Guarantee
Local vector processing. OmniTools renders your clipping coordinates entirely within your local web browser using native W3C CSS shape engines.
Your custom vertex coordinates, generated CSS rules, and visual designs are never transmitted to external servers or persisted in cloud databases.
Frequently Asked Questions
How does the CSS clip-path property work for polygons, circles, and ellipses?
CSS clip-path defines a vector clipping region using polygon(), circle(), ellipse(), or inset() coordinate percentages. Pixels inside the shape remain visible while everything outside is masked cleanly by the browser compositor.
Does CSS clip-path work across all modern desktop and mobile browsers?
Yes. Basic shape functions (polygon, circle, ellipse, inset) in CSS clip-path are natively supported across Chrome, Edge, Firefox, and Safari without vendor prefixes.