CSS shape-image-threshold Property
The CSS shape-image-threshold property sets the minimum opacity level used to determine which parts of an image define a shape for text wrapping.
It works with image-based shapes specified by shape-outside. By adjusting the threshold, developers can control whether partially transparent pixels contribute to the shape's boundary. This is useful for images with soft edges, transparency gradients, or irregular outlines.
shape-image-threshold Syntax
The shape-image-threshold property accepts a number between 0 and 1, inclusive.
Basic Syntax
selector {
shape-image-threshold: 0.5;
}
Available Values
.shape {
shape-image-threshold: 0;
}
.shape {
shape-image-threshold: 0.25;
}
.shape {
shape-image-threshold: 0.5;
}
.shape {
shape-image-threshold: 0.75;
}
.shape {
shape-image-threshold: 1;
}
CSS-Wide Keywords
.shape {
shape-image-threshold: initial;
}
.shape {
shape-image-threshold: inherit;
}
.shape {
shape-image-threshold: unset;
}
.shape {
shape-image-threshold: revert;
}
.shape {
shape-image-threshold: revert-layer;
}
The threshold represents an alpha value, not a color brightness or grayscale level.
Property Values
| Value | Description |
|---|---|
0 |
Includes pixels with alpha values greater than zero. Fully transparent pixels are excluded. |
0.25 |
Includes pixels whose alpha values are greater than 0.25. |
0.5 |
Includes pixels whose alpha values are greater than 0.5. |
0.75 |
Includes pixels whose alpha values are greater than 0.75. |
1 |
Uses the highest threshold. Because alpha values cannot exceed 1, no pixels qualify. |
initial |
Resets the property to 0. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to 0 because it is not inherited. |
revert |
Reverts the property according to CSS cascade origin rules. |
revert-layer |
Reverts the property according to CSS cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | 0 |
| Inherited | No |
| Applies to | Floats |
| Computed value | The specified number, clamped to the range 0 through 1 |
| Animation type | By computed value type (number) |
| Percentages | Not applicable |
| Related properties | shape-outside, shape-margin |
| Specification | CSS Shapes Module Level 1 |
Valid Values
.shape {
shape-image-threshold: 0;
}
.shape {
shape-image-threshold: 0.3;
}
.shape {
shape-image-threshold: 0.5;
}
.shape {
shape-image-threshold: 1;
}
.shape {
shape-image-threshold: 1.5;
}
.shape {
shape-image-threshold: -0.5;
}
Numeric values outside the range from 0 to 1 are accepted but clamped to the nearest endpoint when computed.
Invalid Values
.shape {
shape-image-threshold: 50%;
}
.shape {
shape-image-threshold: 10px;
}
.shape {
shape-image-threshold: auto;
}
.shape {
shape-image-threshold: transparent;
}
.shape {
shape-image-threshold: 0.5 0.8;
}
The property accepts a single number, not percentages, lengths, color keywords, or multiple numeric values.
How It Works
When shape-outside uses an image, the browser examines the image's alpha channel to determine which pixels contribute to the shape.
Step 1: Float an Element
.shape-image {
float: left;
width: 200px;
height: 200px;
}
CSS Shapes affect how inline content wraps around floated elements.
Step 2: Define an Image-Based Shape
.shape-image {
shape-outside: url("/img/transparent-shape.png");
}
The browser uses the image's transparency to calculate the wrapping boundary.
Step 3: Set the Threshold
.shape-image {
shape-image-threshold: 0.5;
}
Pixels with alpha values greater than 0.5 contribute to the shape. Pixels at or below the threshold are excluded.
Step 4: Wrap Text Around the Shape
Text flows around the calculated shape instead of simply following the floated element's rectangular margin box.
Default Behavior
.shape-image {
shape-image-threshold: 0;
}
All pixels with any nonzero opacity contribute to the shape.
Important Consideration
The property changes the shape used for text wrapping. It does not modify the image's appearance, transparency, or visible pixels.
Understanding the Alpha Threshold
The alpha channel represents pixel opacity. An alpha value of 0 is fully transparent, while 1 is fully opaque.
Alpha Value Comparison
| Pixel Alpha | Opacity | Included at Threshold 0.5? |
|---|---|---|
0 |
Fully transparent | No |
0.25 |
25% opaque | No |
0.5 |
50% opaque | No |
0.75 |
75% opaque | Yes |
1 |
Fully opaque | Yes |
Low Threshold
.shape-image {
shape-image-threshold: 0.1;
}
Most visible pixels, including faint transparent edges, contribute to the wrapping shape.
Medium Threshold
.shape-image {
shape-image-threshold: 0.5;
}
Only pixels that are more than 50% opaque contribute to the shape.
High Threshold
.shape-image {
shape-image-threshold: 0.9;
}
Only nearly opaque pixels contribute to the shape.
Threshold of 1
.shape-image {
shape-image-threshold: 1;
}
No pixel has an alpha value greater than 1, so the resulting image-based shape is empty.
Important Consideration
The comparison is strictly greater than the threshold. A pixel whose alpha value exactly matches the threshold is not included.
Using shape-outside
The shape-image-threshold property works with image-based values of shape-outside.
Basic Image Shape
.shape-image {
float: left;
width: 200px;
height: 200px;
shape-outside: url("/img/transparent-shape.png");
shape-image-threshold: 0.5;
}
The browser calculates the wrapping shape from the image's alpha channel.
Using a Gradient
.gradient-shape {
float: left;
width: 200px;
height: 200px;
shape-outside: radial-gradient(circle, black 35%, transparent 75%);
shape-image-threshold: 0.5;
}
Gradients can supply alpha values for shape calculation without requiring an external image file.
Using a Conic Gradient
.gradient-shape {
float: left;
width: 200px;
height: 200px;
shape-outside: conic-gradient(from 0deg, black 0deg 180deg, transparent 180deg 360deg);
shape-image-threshold: 0.5;
}
The threshold determines which portions of the generated image contribute to the shape.
Not Used With Basic Shapes
.circle-shape {
float: left;
shape-outside: circle(50%);
shape-image-threshold: 0.5;
}
The threshold has no effect on the circle() basic shape because its boundary is defined geometrically rather than by image transparency.
Important Consideration
The image used for shape-outside must be available and permitted for shape processing. Cross-origin images may require appropriate CORS permissions.
Working With Image Transparency
The usefulness of shape-image-threshold depends on the alpha values present in the image.
Fully Opaque Images
An image with no transparency generally produces a rectangular image-based shape for thresholds below 1.
Images With Transparent Backgrounds
Images containing fully transparent areas can produce irregular wrapping boundaries that follow their opaque content.
Soft Edges
Images with anti-aliased edges contain partially transparent pixels. Changing the threshold adjusts how much of the soft edge contributes to the shape.
Opacity Gradients
.gradient-shape {
float: left;
width: 220px;
height: 220px;
shape-outside: radial-gradient(circle, black 30%, transparent 80%);
shape-image-threshold: 0.5;
}
The browser includes the portion of the gradient whose alpha values exceed the threshold.
Visual Opacity vs. Shape Opacity
The threshold does not alter the visible image. It only determines which alpha values are included in the wrapping shape.
Important Consideration
Images with sharp transparency boundaries may show little visible difference between threshold values. Soft gradients provide clearer demonstrations.
Combining With shape-margin
The shape-margin property adds space outside the calculated shape, creating separation between the shape and surrounding text.
Basic Combination
.shape-image {
float: left;
width: 200px;
height: 200px;
shape-outside: url("/img/transparent-shape.png");
shape-image-threshold: 0.5;
shape-margin: 15px;
}
The threshold determines the image-based boundary, and shape-margin expands the exclusion area around it.
Without Shape Margin
.shape-image {
shape-image-threshold: 0.5;
shape-margin: 0;
}
Text wraps directly around the calculated shape boundary.
With Additional Spacing
.shape-image {
shape-image-threshold: 0.5;
shape-margin: 20px;
}
Text remains farther away from the shape.
Related Property Comparison
| Property | Purpose |
|---|---|
shape-outside |
Defines the shape around which inline content wraps. |
shape-image-threshold |
Determines which image alpha values contribute to the shape. |
shape-margin |
Adds spacing around the calculated shape. |
Important Consideration
Increasing the threshold can reduce the shape's exclusion area, while increasing shape-margin expands that area. The two properties serve different purposes.
Practical Examples
Transparent PNG Shape
.image-shape {
float: left;
width: 200px;
height: 200px;
shape-outside: url("/img/transparent-shape.png");
shape-image-threshold: 0.5;
}
Uses the alpha channel of a transparent PNG to determine the wrapping boundary.
Soft Gradient Shape
.gradient-shape {
float: left;
width: 200px;
height: 200px;
shape-outside: radial-gradient(circle, black 20%, transparent 80%);
shape-image-threshold: 0.3;
}
A lower threshold includes more of the gradient's partially transparent region.
Tighter Text Wrapping
.gradient-shape {
shape-image-threshold: 0.8;
}
A higher threshold excludes more partially transparent pixels, potentially allowing text to wrap closer to the opaque center.
Shape With Extra Spacing
.image-shape {
shape-image-threshold: 0.5;
shape-margin: 15px;
}
Creates additional space between the calculated shape and surrounding text.
Using a CSS Custom Property
.image-shape {
--alpha-threshold: 0.5;
shape-image-threshold: var(--alpha-threshold);
}
A custom property makes it easier to adjust the threshold consistently.
Responsive Threshold
.image-shape {
shape-image-threshold: 0.3;
}
@media (min-width: 992px) {
.image-shape {
shape-image-threshold: 0.6;
}
}
The threshold changes at the specified viewport breakpoint.
Resetting the Threshold
.image-shape {
shape-image-threshold: 0;
}
Returns to the default behavior, including every pixel with nonzero opacity.
shape-image-threshold Example
This example compares three opacity thresholds using the same radial gradient. The gradient is used as the wrapping shape, allowing text to flow around different portions of its transparency.
HTML Example
<div class="threshold-demo">
<div class="threshold-panel">
<h3>Threshold: 0.1</h3>
<div class="gradient-shape low"></div>
<p>This text wraps around the gradient shape. A low threshold includes more partially transparent pixels, creating a larger exclusion area.</p>
<p>Continue reading to observe the wrapping boundary.</p>
</div>
<div class="threshold-panel">
<h3>Threshold: 0.5</h3>
<div class="gradient-shape medium"></div>
<p>This text wraps around the gradient shape. A medium threshold includes pixels that are more than half opaque.</p>
<p>Continue reading to observe the wrapping boundary.</p>
</div>
<div class="threshold-panel">
<h3>Threshold: 0.9</h3>
<div class="gradient-shape high"></div>
<p>This text wraps around the gradient shape. A high threshold includes only nearly opaque pixels, creating a smaller exclusion area.</p>
<p>Continue reading to observe the wrapping boundary.</p>
</div>
</div>
CSS Example
.threshold-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
gap: 15px;
}
.threshold-demo .threshold-panel {
min-height: 300px;
padding: 15px;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
display: flow-root;
}
.threshold-demo .threshold-panel h3 {
margin-top: 0;
font-size: 1rem;
}
.threshold-demo .gradient-shape {
float: left;
width: 150px;
height: 150px;
margin-right: 5px;
background: radial-gradient(circle, #2563eb 20%, transparent 80%);
shape-outside: radial-gradient(circle, black 20%, transparent 80%);
}
.threshold-demo .low {
shape-image-threshold: 0.1;
}
.threshold-demo .medium {
shape-image-threshold: 0.5;
}
.threshold-demo .high {
shape-image-threshold: 0.9;
}
Threshold: 0.1
This text wraps around the gradient shape. A low threshold includes more partially transparent pixels, creating a larger exclusion area.
Continue reading to observe the wrapping boundary.
Threshold: 0.5
This text wraps around the gradient shape. A medium threshold includes pixels that are more than half opaque.
Continue reading to observe the wrapping boundary.
Threshold: 0.9
This text wraps around the gradient shape. A high threshold includes only nearly opaque pixels, creating a smaller exclusion area.
Continue reading to observe the wrapping boundary.
The first panel uses a low threshold, including most of the gradient's visible area. The second uses a medium threshold, while the third uses a high threshold that produces a smaller wrapping shape.
Comparing the Results
| Threshold | Included Pixels | Typical Result |
|---|---|---|
0.1 |
Alpha greater than 0.1 | Larger wrapping shape |
0.5 |
Alpha greater than 0.5 | Medium wrapping shape |
0.9 |
Alpha greater than 0.9 | Smaller wrapping shape |
Changing the Threshold
.threshold-demo .medium {
shape-image-threshold: 0.75;
}
The medium panel excludes additional partially transparent pixels, reducing the shape's exclusion area.
Adding Shape Margin
.threshold-demo .gradient-shape {
shape-margin: 10px;
}
Text gains additional space around each calculated shape.
Browser Compatibility Note
CSS Shapes require a floated element for text wrapping. The visual result may vary slightly due to browser rendering and text layout.
Accessibility Considerations
Image-based text wrapping can create visually interesting layouts, but readability and content order should remain priorities.
Maintain Readable Text Width
A large wrapping shape can leave narrow lines of text. Ensure enough horizontal space remains for comfortable reading.
Avoid Excessively Tight Wrapping
Use shape-margin to provide separation between the image and surrounding text.
Preserve Logical Reading Order
CSS Shapes change visual wrapping, not the document's source order. Keep the HTML reading sequence meaningful.
Provide Alternative Text
Images that convey information should have appropriate alternative text. Decorative images can use empty alternative text.
Test Text Zoom
Verify that text remains readable when users enlarge fonts or zoom the page.
Responsive Layouts
Consider disabling complex shapes on narrow screens when they leave insufficient room for text.
@media (max-width: 600px) {
.shape-image {
float: none;
shape-outside: none;
}
}
Avoid Using Shapes for Essential Information
Text wrapping shapes should enhance presentation rather than communicate information that cannot be understood without the visual effect.
Common Mistakes
Using Percentages
.shape {
shape-image-threshold: 50%;
}
The property accepts a number, not a percentage. Use 0.5 instead.
Using Pixel Values
.shape {
shape-image-threshold: 10px;
}
Threshold values represent opacity, not distance.
Expecting the Property to Change Image Opacity
The property affects text wrapping only. It does not modify the visible image.
Forgetting shape-outside
The threshold has no useful effect without an image-based shape-outside value.
Forgetting to Float the Element
CSS Shapes control text wrapping around floated elements. A non-floated element does not produce the same wrapping behavior.
Using a Basic Shape
.shape {
shape-outside: circle(50%);
shape-image-threshold: 0.5;
}
The threshold does not change the boundary of a geometric circle() shape.
Confusing Alpha With Brightness
The property compares opacity values, not pixel brightness or color intensity.
Expecting a Difference With Fully Opaque Images
Images without transparency generally produce the same rectangular shape for thresholds below 1.
Using a Threshold of 1
A threshold of 1 produces an empty image-based shape because no pixel can exceed full opacity.
Ignoring Image Security Restrictions
Cross-origin images may not be usable for shape calculation unless appropriate permissions are provided.
Assuming Inheritance
The property is not inherited. Apply it directly to each floated element that needs a threshold.
Ignoring Responsive Text Wrapping
Large shapes can leave insufficient room for text on smaller screens.
Important Considerations
Keep the following points in mind when using shape-image-threshold:
- It determines which image alpha values contribute to a CSS wrapping shape.
- The initial value is
0. - The property is not inherited.
- It applies to floated elements.
- It works with image-based
shape-outsidevalues. - The threshold is represented by a number.
- Values are clamped to the range from
0to1. - Pixels must have alpha values greater than the threshold to be included.
- A threshold of
0includes all pixels with nonzero opacity. - A threshold of
1produces an empty image-based shape. - Higher thresholds generally produce smaller exclusion areas for soft-edged images.
- Lower thresholds include more partially transparent pixels.
- The property does not change the visible image.
- It does not affect the boundaries of geometric basic shapes.
- Transparent PNG images and CSS gradients can provide alpha information.
- Cross-origin image restrictions may affect image-based shapes.
- Use
shape-marginto add spacing around the calculated shape. - Ensure enough space remains for readable text.
- Test responsive layouts and text zoom.
- Use CSS Shapes as a visual enhancement rather than a replacement for meaningful document structure.
Browser Support
The CSS shape-image-threshold property is widely available in modern browsers, including current versions of Chrome, Edge, Firefox, and Safari.
Support depends on the browser's implementation of CSS Shapes and image-based shape-outside values. The property affects text wrapping only when an eligible floated element uses an image-based shape.
For current compatibility information, visit Can I Use? and search for shape-image-threshold.
Feature Detection
@supports (shape-image-threshold: 0.5) {
.shape-image {
shape-image-threshold: 0.5;
}
}
Feature queries can be used to apply threshold styling when the browser recognizes the property.
Fallback Behavior
When unsupported, the browser ignores the declaration. Text wrapping follows the remaining supported float and shape rules.
Image Security Requirements
Browsers may reject image-based shapes when the image cannot be used safely for alpha-channel processing. Use same-origin images or appropriately configured cross-origin resources.
Specifications
The shape-image-threshold property is defined in the CSS Shapes Module Level 1 specification.
The specification defines how an image's alpha channel and the specified threshold determine the shape used for text wrapping.
For additional documentation and examples, consult MDN Web Docs.
