Vector Compositing

SVG Clipping, Masking & Blend Modes Guide

Deep architectural guide to vector compositing: building non-destructive icon notification cutouts, luminance alpha gradients, and GPU blend modes.

TL;DR — The Vector Compositing Rulebook

Clip for geometry, mask for alpha: Use <clipPath> when you need hard, razor-sharp vector cutouts (like a notification badge cutout on a bell icon) with zero GPU overhead. Use <mask> when you need soft gradient fades or luminance-based opacity. Use CSS mix-blend-mode: multiply or overlay inside SVG trees for complex vector duotone themes without modifying path geometries.

The Difference: Clipping vs Masking

While both clipping and masking restrict visual rendering to a designated area, their underlying mathematical and rendering pipelines are completely distinct:

1. The Non-Destructive Notification Badge Cutout Pattern

A classic UI design problem: you have a bell icon and want to place an unread notification dot in the top-right corner. If the dot overlaps the bell stroke, placing a circle with a background-colored border breaks whenever the icon is placed over gradients, dark mode surfaces, or image cards.

The solution is an inverted SVG mask that punches an actual mathematical hole through the bell icon:

<svg viewBox="0 0 24 24" width="24" height="24">
  <defs>
    <mask id="badge-hole">
      <!-- Everything white stays visible -->
      <rect width="100%" height="100%" fill="white" />
      <!-- Black circle punches a transparent hole where the badge sits -->
      <circle cx="18" cy="6" r="5" fill="black" />
    </mask>
  </defs>

  <!-- Bell Icon masked with the hole -->
  <path 
    d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9M13.73 21a2 2 0 0 1-3.46 0" 
    fill="none" 
    stroke="currentColor" 
    stroke-width="2" 
    mask="url(#badge-hole)" 
  />

  <!-- Red Notification Dot sits in the center of the punched cutout -->
  <circle cx="18" cy="6" r="3" fill="#EF4444" />
</svg>

Because the cutout is physically transparent, the icon looks pristine on any surface, dark mode background, or blurred glass card.

2. Responsive Clipping with clipPathUnits="objectBoundingBox"

By default, <clipPath> uses absolute user space pixels. If you want a clipping path to automatically scale across differently sized icons or hero banners, use clipPathUnits="objectBoundingBox":

<svg width="0" height="0">
  <defs>
    <clipPath id="squircle" clipPathUnits="objectBoundingBox">
      <!-- Coordinates normalized from 0.0 to 1.0 -->
      <path d="M 0,0.5 C 0,0 0,0 0.5,0 C 1,0 1,0 1,0.5 C 1,1 1,1 0.5,1 C 0,1 0,1 0,0.5 Z" />
    </clipPath>
  </defs>
</svg>

<!-- Applied via CSS to any HTML or SVG element of any size -->
<style>
  .app-icon {
    clip-path: url(#squircle);
  }
</style>

3. CSS Blend Modes Inside SVG Vectors

CSS blend modes allow vectors to create sophisticated lighting and duotone effects without raster Photoshop exports. Applying mix-blend-mode inside an SVG canvas composites shapes directly on the GPU:

<svg viewBox="0 0 24 24" width="48" height="48">
  <!-- Base Vector Shape -->
  <circle cx="12" cy="12" r="10" fill="#3B82F6" />

  <!-- Highlight with Screen Blend Mode -->
  <path 
    d="M 6,6 Q 12,2 18,6" 
    stroke="#FFFFFF" 
    stroke-width="3" 
    style="mix-blend-mode: overlay; opacity: 0.8;" 
  />

  <!-- Shadow with Multiply Blend Mode -->
  <ellipse 
    cx="12" cy="18" rx="7" ry="2" 
    fill="#000000" 
    style="mix-blend-mode: multiply; opacity: 0.4;" 
  />
</svg>

Performance & Hardware Acceleration

Rendering Cost Optimization

Never animate <mask> properties on 100+ items simultaneously: Luminance masks force the browser's CPU/GPU to recalculate alpha channel raster buffers on every single frame. For high-frequency hover animations, stick to <clipPath> transforms or pure CSS transform: translate3d().

Frequently Asked Questions

Can I use an external SVG file as a CSS clip-path?

Yes. You can reference external SVG clips via clip-path: url('/sprites/shapes.svg#squircle'). However, for Safari/WebKit cross-origin compatibility, inlining the <defs> block in your main HTML document is the most reliable approach.

Why does my SVG mask disappear on Safari?

Safari requires explicit mask-type: luminance or mask-type: alpha CSS property declarations when applying masks to HTML elements from SVG definitions.

Ready to Build Advanced Vector Interfaces?

Search 134,000+ open-source SVG icons across 28 curated libraries on IconStash. Fast, clean, and 100% open source.

Search All 134K+ Icons →