Color scheme

Clip Path and Mask Image

Every element in CSS paints as a rectangle. Shadows, gradients, and filters can change how that rectangle looks, but they cannot change its shape. clip-path and mask-image break that constraint. Both properties hide parts of an element, but they do it in fundamentally different ways: clipping cuts along a hard geometric edge, while masking fades pixels out gradually using an alpha or luminance map. Learning both together is the best way to understand when each is the right tool.

This page covers clip-path first (the simpler, more widely supported property), then mask-image (the more powerful but prefix-heavier property), and ends with a direct comparison so you can make confident choices in your own work.

clip-path: Geometric Clipping

The clip-path property defines a clipping region. Anything inside the region is visible. Anything outside is invisible. The boundary is always a hard edge with no partial transparency. The element still occupies its original rectangular space in the layout; clipping only affects what is painted, not what is measured.

Shape Functions

CSS provides several shape functions for defining clip regions. Each one produces a different kind of geometry:


        /* Circle: centered, 40% radius */
        .avatar {
            clip-path: circle(40%);
        }

        /* Ellipse: horizontal and vertical radii */
        .badge {
            clip-path: ellipse(50% 35% at center);
        }

        /* Inset: rectangular crop with optional rounded corners */
        .frame {
            clip-path: inset(10% round 1rem);
        }

        /* Polygon: arbitrary shape defined by vertex coordinates */
        .diamond {
            clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
        }
    

circle() and ellipse() are straightforward. inset() is useful for cropping edges off an image or creating a rounded rectangle that differs from border-radius (clipped content is truly invisible, not just hidden behind rounded corners). polygon() is the most flexible because you define each vertex as an x/y percentage or length, letting you create triangles, hexagons, arrows, diagonal slices, or any other straight-edged shape.

There is also path(), which accepts an SVG path string for curves and complex shapes, but browser support and authoring complexity make it less practical for most day-to-day work. Tools like Clippy let you visually draw clip paths and copy the CSS, which is far easier than writing polygon coordinates by hand.

Diagonal Sections and Angled Dividers

One of the most common uses for clip-path is creating angled section dividers without images. A polygon that slices the bottom edge at an angle gives a section a dynamic, non-rectangular boundary:


        /* Angled bottom edge */
        .hero {
            clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
        }
    

The four vertices define the full width at the top and a slanted cut at the bottom. The next section's background fills the gap naturally. This technique is cleaner than using rotated pseudo-elements or SVG dividers because it is a single property on the element itself with no extra markup.

Transitions and Hover Effects

clip-path is animatable, but only when the starting and ending shapes use the same function with the same number of points. You can transition a circle() from a small radius to a large one, or morph a polygon() from one set of vertices to another as long as both polygons have the same number of vertices:


        .reveal {
            clip-path: circle(0% at center);
            transition: clip-path 0.5s ease;
        }

        .reveal:hover {
            clip-path: circle(75% at center);
        }
    

The pitfall is mismatched shapes. You cannot transition from circle() to polygon(), or from a four-point polygon to a six-point polygon. The browser has no way to interpolate between fundamentally different geometries, so it will snap instantly instead of animating. If you need a shape morph between different vertex counts, the workaround is to pad the simpler shape with duplicate vertices so both sides have the same count.

Clipped content is invisible but still there. A clipped element still receives pointer events across its full rectangular area unless you also set pointer-events: none on the invisible region. This matters for click targets: a circular avatar clipped with clip-path: circle() still has a rectangular hit area.

mask-image: Alpha and Luminance Masking

Where clip-path draws a hard boundary, mask-image uses a grayscale image (or gradient) to control which pixels are visible and how visible they are. White areas of the mask are fully visible, black areas are fully hidden, and gray areas are partially transparent. This lets you create soft fades, vignettes, and complex reveal patterns that no clip path can produce.

A Note on the -webkit- Prefix

For years, mask-image required a -webkit- prefix in Chrome, Safari, and Edge. You will still see -webkit-mask-image in most tutorials and production codebases because of that history. The good news is that all current major browsers now support the unprefixed property: Chrome since version 120, Safari since 15.4, Firefox since 53, and Edge since 120. Global support sits above 96%.

Including both the prefixed and unprefixed versions is still reasonable if your audience includes older devices, but it is no longer the emergency it once was. If your build tool handles prefixing automatically (Lightning CSS, Autoprefixer), you can write the unprefixed version and let the tooling decide:


        /* Unprefixed is enough for all current browsers.
           Include the prefix if you need older coverage. */
        .fade-out {
            -webkit-mask-image: linear-gradient(black, transparent);
            mask-image: linear-gradient(black, transparent);
        }
    

Gradient Masks for Fading Edges

The most common use for mask-image is fading an element's edges so content dissolves instead of ending abruptly. A linear gradient from black (visible) to transparent (hidden) creates a smooth fade:


        /* Fade the bottom edge of a scrollable container */
        .scroll-fade {
            -webkit-mask-image: linear-gradient(
                to bottom,
                black 70%,
                transparent 100%
            );
            mask-image: linear-gradient(
                to bottom,
                black 70%,
                transparent 100%
            );
        }
    

This is useful for scrollable containers, image galleries, and any situation where content needs to visually dissolve into the background rather than hitting a hard edge. You can also use radial gradients for a vignette-style mask that fades the corners while keeping the center sharp.

SVG and Image Masks

Beyond gradients, mask-image accepts any image URL. An SVG with transparent and opaque regions works as a shape mask, and a bitmap with varying brightness works as a luminance mask (if you set mask-mode: luminance). This lets you create text cutout effects, decorative borders, and complex reveal shapes that would be impossible with clip-path:


        /* SVG shape mask */
        .masked {
            -webkit-mask-image: url('/images/splatter.svg');
            mask-image: url('/images/splatter.svg');
            -webkit-mask-size: cover;
            mask-size: cover;
        }
    

Debugging mask-size and mask-repeat

A common frustration with mask-image is that the mask tiles by default, just like background-image. If your mask is smaller than the element, it repeats and creates an unexpected pattern. The fix is the same as with backgrounds: set mask-size and mask-repeat explicitly:


        .masked {
            -webkit-mask-image: url('/images/mask.svg');
            mask-image: url('/images/mask.svg');
            -webkit-mask-size: contain;
            mask-size: contain;
            -webkit-mask-repeat: no-repeat;
            mask-repeat: no-repeat;
            -webkit-mask-position: center;
            mask-position: center;
        }
    

If your mask appears to do nothing, check these three things first: Is the mask image loading? (DevTools Network panel.) Is it tiling when you expected it to cover? (Set mask-size: cover or contain.) Is the mask mode correct? (Default is alpha, which uses transparency. Switch to luminance if your mask uses brightness instead of alpha.)

When to Use Which

The choice between clipping and masking comes down to the kind of edge you need:

  • Hard geometric edges (circles, polygons, diagonal cuts, hexagons): Use clip-path. It is simpler, has no prefix concerns, and supports transitions between same-type shapes.
  • Soft fades, gradual transparency, or complex shapes from images: Use mask-image. It handles partial transparency that clip paths cannot express.
  • Animatable shape reveals: Use clip-path with matching vertex counts. Mask images are not smoothly animatable in the same way.
  • Broad browser support without prefixes: clip-path wins. mask-image still requires -webkit- in most shipping browsers.

In practice, clip-path handles about 80% of non-rectangular layout needs. Reach for mask-image when you need the soft edges or image-based shapes that clipping cannot produce.

Guided Demos

The first demo lets you switch between clip-path shape functions on an image. The second shows a gradient mask fading the bottom edge of a photo. Use the theme toggle to verify both work in light and dark mode:

Clip Path Shapes

Clip Path Shapes

Color scheme
Sample photo for clip path demo
clip-path: circle(42%);

Gradient Mask Fade

This demo applies a gradient mask to the bottom edge of a photo. The image dissolves into the background instead of ending with a hard edge:

Gradient Mask Fade

Color scheme
Sample landscape photo with gradient mask fade
-webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%); mask-image: linear-gradient(to bottom, black 50%, transparent 100%);

Teaching Video Checklist

When you record your teaching video, make sure your teammates come away understanding these concepts:

  • The core difference between clipping (hard geometric edge, nothing outside is painted) and masking (per-pixel transparency controlled by an image or gradient)
  • At least three clip-path shape functions demonstrated live: circle(), polygon(), and one more of your choice
  • A clip-path transition or hover effect, with an explanation of why both states must use the same function and vertex count
  • A mask-image demo using a gradient mask, with a brief mention of the -webkit- prefix history and current browser support status
  • The mask-size and mask-repeat gotcha: why masks tile by default and how to fix it
  • A clear one-sentence summary of when to use clip-path versus mask-image

Walk both demos in DevTools so your teammates can see the property values changing in real time. Show what happens when you remove the mask prefix in a WebKit browser and when you transition between polygons with different vertex counts.

Resources