Clip-path, Masks and Blend Modes

Intermediate · 8 min

Three ways to change an element's pixels without editing an image: cut them away with clip-path, fade them with mask-image, or blend them with what's behind.

Before thisBox Shadows and Filters

CSSnippets · 8 min

Clip-path, Masks and Blend Modes

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by CSSnippetsReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • `clip-path` is a hard-edged cookie cutter: pixels outside the shape are not painted and are not clickable. It takes `circle()`, `ellipse()`, `inset()`, `polygon()`, `path()` and the newer `shape()`.
  • `clip-path` clips everything the element paints, including its own `box-shadow`. Put a `filter: drop-shadow()` on a wrapper to shadow the clipped shape.
  • `mask-image` is the soft version: the alpha (or luminance) of a gradient or image decides how opaque each pixel is, so you can fade an edge instead of cutting it.
  • `mix-blend-mode` blends an element with whatever is painted behind it in the same stacking context. `multiply` darkens, `screen` lightens, `difference` inverts by contrast. `isolation: isolate` limits what it blends with.
  • `background-blend-mode` does the same between the background layers of a single element, so a photo and a color can be combined without touching the HTML.

Changing pixels without an image editor

Box shadows and filters change how an element looks around its edges. These three tools change the element’s pixels themselves, each in a different way. Think of a photo on a table. clip-path is scissors, mask-image is a sheet of tracing paper laid over it with some parts see-through, and a blend mode is how that photo’s colors mix with whatever it lies on.

clip-path defines a region. Anything outside it is not painted:

.avatar  { clip-path: circle(50%); }
.banner  { clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%); }   /* slanted bottom */
.arrow   { clip-path: polygon(0 0, 70% 0, 100% 50%, 70% 100%, 0 100%); }
.rounded { clip-path: inset(10px round 16px); }

polygon() takes a list of x y points, which you can read as connect-the-dots from the top-left corner; percentages are relative to the box. circle() and ellipse() take a radius and an at position. path() takes SVG path data in pixels, and the newer shape() function describes curves with CSS units. shape() became available across browsers in early 2026, so check support before relying on it. Basic shapes have been Baseline for years.

Two behaviors surprise people:

  • Clipped pixels are not clickable. Regions outside the shape don’t receive pointer events. In a Chromium test, a 100px square clipped to a 30px circle returned the page body for a point at its corner and the element itself for a point at its center.
  • Everything gets cut, shadows included. A box-shadow is painted outside the box, so a clip removes it. The fix is one wrapper element:
.shadow-wrap { filter: drop-shadow(0 6px 10px rgb(0 0 0 / 0.3)); }
.shadow-wrap > .hex { clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }

The inner element is clipped, then the wrapper’s filter shadows the result.

A clip-path also creates a stacking context, like filter does.

mask: the soft version

A clip is binary: in or out. A mask lets each pixel be partly visible, using the transparency of an image or gradient:

.fade-bottom {
  mask-image: linear-gradient(to bottom, black 60%, transparent);
}
.logo-shape {
  mask: url("star.svg") center / contain no-repeat;
  background: linear-gradient(135deg, #f43f5e, #6366f1);
}

Where the mask is opaque the element shows through; where it is transparent, it is hidden. For images and gradients the default mode reads only alpha, so the mask’s color doesn’t matter and black is just a conventional opaque value. The second example is a good use of the idea: the element is a gradient, and the mask cuts it into a star-shaped icon, so the icon can take any color. mask-size, mask-repeat, mask-position and mask-composite behave like their background- cousins, and the unprefixed mask properties have been in every major browser since December 2023.

Blend modes: mixing with what’s behind

mix-blend-mode changes how an element’s colors combine with the pixels under it, instead of just covering them:

.title { color: white; mix-blend-mode: difference; }   /* inverts against any background */
.stamp { mix-blend-mode: multiply; }                   /* white drops out, color darkens */

Each mode is a formula per color channel. multiply multiplies channels, so a red box over a blue one gives black, and white is a no-op. screen is the inverse, so red over blue gives magenta. Both results were confirmed by sampling screenshot pixels in a browser. overlay, soft-light and color-dodge are variations used in photo effects.

Blending happens against everything painted behind in the same stacking context. If a blended element seems to blend with the wrong thing, or nothing, put isolation: isolate on the ancestor that should be the boundary. background-blend-mode runs the same math between the background layers of one element, so background: url(photo.jpg), #4f46e5; background-blend-mode: multiply; tints a photo with no extra markup.

What the video covers

CSSnippets’ “Master CSS Clip-Path: Create Custom Shapes with One Line of Code!” is about eight minutes, from April 2025. Its description lists inset() for cropping and inner cutouts, circle() and ellipse(), custom shapes with polygon(), and smooth animations, with examples such as a hero section. I could not read a transcript, so I describe no more than that. It covers clip-path only. Masks and blend modes come from the prose here and from the two runner-up videos, which are older (2022 and 2021) but cover properties that haven’t changed.

Where this fits

Clipping, masking and blending each create a stacking context, which is the subject of stacking contexts and z-index. The shapes you clip with are the same coordinates transforms move around, and you can transition between two polygon() clips that have the same number of points.

Check yourself

  1. 01You clip a card to a hexagon with `clip-path` and add a `box-shadow`. No shadow appears. Why?

    The clip is applied to everything the element paints, and a box-shadow is painted outside the box, so it is cut away. Wrap the card in a parent and apply `filter: drop-shadow(...)` to the wrapper; the filter runs on the already-clipped result.

  2. 02A button is clipped with `clip-path: circle(30px)` but the corners of its original rectangle still show a pointer cursor. True or false?

    False. Clipped-away regions don't receive pointer events. In Chromium, `elementFromPoint` at a corner outside the circle returns the element underneath, not the clipped one.

  3. 03How would you fade an image to transparent along its bottom edge?

    `mask-image: linear-gradient(to bottom, black 60%, transparent)`. Black parts of the mask keep the image fully visible, transparent parts hide it, and the gradient in between gives a smooth fade.

  4. 04What does `mix-blend-mode: multiply` do with a red element over a blue background?

    Multiply multiplies the color channels. Red `(255, 0, 0)` times blue `(0, 0, 255)` gives black `(0, 0, 0)`. Multiplying with white leaves a color unchanged, which is why multiply makes white backgrounds in images disappear.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark