πŸ–ΌοΈ Mastering shape-image-threshold in CSS

πŸ“Œ What Is shape-image-threshold?

The shape-image-threshold property controls how much of an image's alpha channel (transparency) is used to compute the shape for shape-outside.
It is ONLY used when shape-outside is set to url() or an image-based shape.
In simple words:It determines what parts of an image count as β€œsolid enough” for text to wrap around.

>>β€œshape-image-threshold adjusts how strict the image silhouette is when wrapping text.”

🧩 Basic Syntax

Syntax

shape-image-threshold: <number>;   /* value between 0 and 1 */

shape-image-threshold: 0;     /* loose threshold */
shape-image-threshold: 0.5;   /* medium cutoff */
shape-image-threshold: 1;     /* strict threshold: only fully opaque pixels count */

βœ” Value range: 0 β†’ 1
βœ” Higher value = stricter mask
βœ” Lower value = softer, more inclusive shape

🎯 How It Works

  • 0 β†’ everything with ANY opacity counts (very soft silhouette)
  • 1 β†’ only fully opaque pixels count (sharp silhouette)
  • Values in between adjust how aggressively transparent areas are removed

πŸ§ͺ Example: Image Shape With Soft Silhouette

Threshold 0 (soft)

.shape-soft {
  float: left;
  width: 250px;
  height: 250px;
  shape-outside: url(star.png);
  shape-image-threshold: 0;
  shape-margin: 10px;
  background: url(star.png) center/contain no-repeat;
}

βœ” The shape includes even low-opacity areas
βœ” Great for soft glow-like silhouettes

πŸ§ͺ Example: Medium Threshold

Threshold 0.5 (balanced)

.shape-mid {
  float: left;
  width: 250px;
  height: 250px;
  shape-outside: url(blob.png);
  shape-image-threshold: 0.5;
  shape-margin: 10px;
}

βœ” Removes lightly transparent pixels
βœ” Good for most PNG artwork with soft edges

πŸ§ͺ Example: Strict Ξ± Cutoff

Threshold 1 (sharp edges)

.shape-strict {
  float: left;
  width: 250px;
  height: 250px;
  shape-outside: url(png-shape.png);
  shape-image-threshold: 1;
  background: url(png-shape.png) center/contain no-repeat;
}

βœ” Only 100% opaque pixels define the shape
βœ” Perfect for hard-edged icons or stencils

🌈 Visual Summary

ThresholdEffect
0Very soft edges, almost entire image considered solid
0.5Balanced β€” medium transparency trimmed
1Only completely opaque regions used

πŸ”₯ Advanced Example: Creating Clearer Wrapping Around an Irregular Shape

Clear silhouette

.leaf {
  float: right;
  width: 300px;
  height: 300px;
  shape-outside: url(leaf.png);
  shape-image-threshold: 0.85;
  shape-margin: 15px;
}

βœ” Removes semi-transparent fringes
βœ” Produces a much cleaner text wrap

🎨 Combining shape-outside + shape-margin + shape-image-threshold

Full combo

.combo {
  float: left;
  width: 260px;
  height: 260px;
  shape-outside: url(logo.png);
  shape-image-threshold: 0.6;
  shape-margin: 20px;
  background: url(logo.png) center/contain no-repeat;
}

βœ” Smooth control
βœ” Best for image-based wrapping

πŸ› οΈ Best Practices

  • Use 0–0.4 for soft silhouettes
  • Use 0.5–0.8 for balanced shapes
  • Use 0.9–1 for crisp shapes (icons, logos)
  • Always pair with shape-margin for readability
  • Use high-quality PNG/SVG with transparency for best results

⚠️ Browser Support

  • βœ” Chrome
  • βœ” Safari
  • βœ” Edge
  • ❌ Firefox does NOT support image shapes (including threshold)

Note

shape-image-threshold only works with image-based shapes, not basic shapes like circle() or polygon().

πŸ” Debugging Tips

  • If text ignores the shape β†’ ensure the element is floated
  • Set a fixed width + height on the floated element
  • Adjust threshold until the silhouette feels natural
  • Check PNG transparency β€” the alpha channel must exist
  • Use a temporary clip-path to visualize shape boundaries

πŸ”— Helpful Tools & Resources

>>β€œshape-image-threshold lets you sculpt how precisely your text wraps around an image β€” from soft to razor sharp.” ✨