Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Filters, Masks and Shapes

The shape-image-threshold property

Reference for the CSS shape-image-threshold property: how the alpha cutoff decides which pixels of an image or gradient count as the shape for shape-outside.

The shape-image-threshold property works together with shape-outside when the shape comes from an image or a gradient. It sets the alpha cutoff: pixels whose opacity is greater than the threshold belong to the shape, and text wraps around them. Pixels at or below the threshold are treated as empty space, so text may flow into them.

The value is a number from 0 to 1. With the default 0, any pixel that is not fully transparent counts as part of the shape.

CSS
.float-shape {
  float: left;
  shape-outside: linear-gradient(to left, transparent, black);
  shape-image-threshold: 0.5;
}

Try it

Two thresholds on the same gradient

The gradient is opaque on the left and fades to transparent on the right. With a low threshold the shape reaches almost to the right edge, so the text starts there; with a high threshold only the opaque left strip counts, so the text slides in under the faded part. Text wraps against the shape's right edge because the box floats left.

Syntax

CSS
shape-image-threshold: <number>;
Initial value 0
Applies to Floats
Inherited No
Animatable Yes (as a number)
Computed value The number, clamped to the range 0 to 1

Values

Value Description
<number> The alpha cutoff. Values below 0 are treated as 0, values above 1 as 1. A pixel is part of the shape when its alpha is greater than this number.

Usage notes

  • Only for image-based shapes. The property has no effect when shape-outside uses a basic shape such as circle() or inset(), or the margin-box keywords.
  • Needs transparency. A fully opaque image has the same alpha everywhere, so the threshold changes nothing. Use a PNG, WebP or SVG with transparent areas, or a gradient that fades out.
  • Floats only. Like shape-outside, it applies to floated elements.
  • Cross-origin images. An image used for shape-outside must be fetched with CORS permission. A file from another origin without the right headers is ignored and no shape is applied. Gradients and same-origin files avoid the problem.
  • Soft edges. Anti-aliased edges contain partly transparent pixels; raising the threshold trims that fringe so text does not hug a blurry edge too tightly.
  • Pair with shape-margin. Add shape-margin to keep text a comfortable distance from the outline.

Browser support

Supported in current versions of Chrome, Edge, Safari and Firefox along with shape-outside; check a compatibility table if you must support older browsers.