CSS flood-opacity Property

The flood-opacity property controls the opacity of the color generated by an SVG <feflood> filter primitive.

It works with flood-color to create opaque, partially transparent, or fully transparent flood images. These images can be combined with other SVG filter primitives to produce colored shadows, overlays, silhouettes, and graphical effects.

flood-opacity Syntax

The flood-opacity property accepts a number or percentage that determines the opacity of the flood image.

Basic Syntax

selector {
  flood-opacity: 0.5;
}

Common Values

.flood-one {
  flood-opacity: 0;
}
.flood-two {
  flood-opacity: 0.25;
}
.flood-three {
  flood-opacity: 0.5;
}
.flood-four {
  flood-opacity: 0.75;
}
.flood-five {
  flood-opacity: 1;
}

Percentage Values

.flood {
  flood-opacity: 50%;
}

CSS-Wide Keywords

.flood {
  flood-opacity: inherit;
}
.flood {
  flood-opacity: initial;
}
.flood {
  flood-opacity: unset;
}
.flood {
  flood-opacity: revert;
}
.flood {
  flood-opacity: revert-layer;
}

The initial value is 1, representing full opacity. The property is inherited and is intended for SVG <feflood> filter primitives.

Property Values

The flood-opacity property uses numeric or percentage values to control transparency.

Value Description
0 Fully transparent flood image.
0.25 25% opacity.
0.5 50% opacity.
0.75 75% opacity.
1 Fully opaque flood image. This is the initial value.
50% Equivalent to 0.5.
100% Equivalent to 1.

Values outside the range from 0 to 1 are clamped to that range for rendering. For example, 1.5 renders as fully opaque, while -0.2 renders as fully transparent.

CSS-Wide Values

Value Description
inherit Uses the computed flood-opacity value of the parent element.
initial Restores the initial value, 1.
unset Uses the inherited value because flood-opacity is inherited.
revert Reverts the property according to the CSS cascade origins.
revert-layer Reverts the property according to the CSS cascade layers.

Property Characteristics

Characteristic Value
Initial value 1
Inherited Yes
Applies to <feflood> elements
Computed value Specified number or percentage
Animation type By computed value type
Percentages Relative to the opacity range from 0 to 1

Opacity values can be animated to create gradual changes in the transparency of a flood image.

How It Works

The <feflood> filter primitive generates a uniform color image. The flood-opacity property determines how transparent that image is.

Step 1: Define an SVG Filter

<svg xmlns="http://www.w3.org/2000/svg">
  <defs>
    <filter id="opacity-flood">
      <feflood flood-color="#336699" flood-opacity="0.5"/>
    </filter>
  </defs>
</svg>

Step 2: Apply the Filter

<rect x="10" y="10" width="160" height="80" filter="url(#opacity-flood)"/>

The filter generates a blue flood image with 50% opacity.

Step 3: Control Opacity with CSS

feflood {
  flood-opacity: 0.5;
}

The CSS declaration sets the opacity of matching <feflood> elements.

Step 4: Adjust the Opacity

feflood {
  flood-color: #336699;
  flood-opacity: 0.25;
}

The flood image becomes more transparent as the opacity value decreases.

Important Distinction

A flood image is generated independently of the original graphic. A partially transparent flood does not automatically blend with the source image. Additional filter primitives are needed when the two images should be combined.

flood-opacity: 0

The value 0 makes the generated flood image fully transparent.

Syntax

feflood {
  flood-opacity: 0;
}

SVG Example

<feflood flood-color="blue" flood-opacity="0"/>

How It Works

The flood primitive still produces an image, but its pixels have zero alpha and therefore contribute no visible color when composited normally.

Important Consideration

A fully transparent flood is not the same as removing the filter. Other primitives in the filter chain can still operate on the transparent result.

Partial Opacity

Values between 0 and 1 create partially transparent flood images.

25% Opacity

feflood {
  flood-opacity: 0.25;
}

50% Opacity

feflood {
  flood-opacity: 0.5;
}

75% Opacity

feflood {
  flood-opacity: 0.75;
}

Common Uses

Partial opacity is useful for soft shadows, translucent overlays, subtle highlights, and effects that combine generated colors with existing graphics.

Important Consideration

The visible appearance depends on what is behind the flood image and how the filter result is composited. The same opacity value can appear different over light and dark backgrounds.

flood-opacity: 1

The value 1 produces a fully opaque flood image when the specified flood color itself has full alpha.

Syntax

feflood {
  flood-opacity: 1;
}

SVG Example

<feflood flood-color="#336699" flood-opacity="1"/>

How It Works

The flood image uses the specified color without additional transparency from flood-opacity.

Initial Value

Because 1 is the initial value, the property can be omitted when a fully opaque flood is desired.

Important Consideration

If flood-color includes an alpha component below 1, setting flood-opacity: 1 does not remove that color transparency.

Percentage Values

The flood-opacity property supports percentage values as an alternative to numbers.

Percentage Syntax

feflood {
  flood-opacity: 50%;
}

Equivalent Values

Number Percentage
0 0%
0.25 25%
0.5 50%
0.75 75%
1 100%

CSS Example

.flood-light {
  flood-opacity: 20%;
}
.flood-medium {
  flood-opacity: 50%;
}
.flood-strong {
  flood-opacity: 80%;
}

Important Consideration

Numbers and percentages represent the same opacity range. For compatibility with older SVG implementations, numeric values are a straightforward choice.

Working with flood-color

The flood-color property determines the color of the generated flood image, while flood-opacity determines its transparency.

Blue Flood with Full Opacity

feflood {
  flood-color: #336699;
  flood-opacity: 1;
}

Blue Flood with Partial Opacity

feflood {
  flood-color: #336699;
  flood-opacity: 0.4;
}

Red Flood with Partial Opacity

feflood {
  flood-color: #cc3333;
  flood-opacity: 0.4;
}

Changing Color and Opacity Independently

The two properties can be adjusted separately. Changing flood-color changes the hue or other color components, while changing flood-opacity changes transparency.

Important Consideration

The flood-color property is not equivalent to fill, and flood-opacity is not equivalent to fill-opacity. Flood properties control the generated image of an SVG filter primitive.

Color Alpha and Flood Opacity

A CSS color can include its own alpha component. When that color is used with flood-opacity, both values contribute to the final transparency.

Color with 50% Alpha

feflood {
  flood-color: rgb(51 102 153 / 50%);
  flood-opacity: 1;
}

The resulting flood image has approximately 50% opacity.

Color Alpha and Flood Opacity Combined

feflood {
  flood-color: rgb(51 102 153 / 50%);
  flood-opacity: 0.5;
}

The color alpha and flood opacity are multiplied, producing approximately 25% final opacity.

Transparency Comparison

Color Alpha flood-opacity Resulting Alpha
100% 1 100%
100% 0.5 50%
50% 1 50%
50% 0.5 25%
25% 0.5 12.5%

Important Consideration

When troubleshooting unexpected transparency, check both the alpha component of flood-color and the value of flood-opacity.

Using flood-opacity in SVG Filters

The flood-opacity property is used with the SVG <feflood> primitive, which creates a uniform color image within its filter primitive region.

Basic SVG Filter

<svg viewBox="0 0 220 120" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <filter id="blue-overlay">
      <feflood flood-color="#336699" flood-opacity="0.5"/>
    </filter>
  </defs>
  <rect x="20" y="20" width="180" height="80" filter="url(#blue-overlay)"/>
</svg>

The filter outputs a semi-transparent blue flood image within its filter region.

CSS Styling

#blue-overlay feflood {
  flood-color: #336699;
  flood-opacity: 0.5;
}

Using a Named Result

<filter id="named-flood">
  <feflood flood-color="#336699" flood-opacity="0.5" result="flood"/>
  <feComposite in="flood" in2="SourceAlpha" operator="in"/>
</filter>

The result attribute names the flood image so another filter primitive can use it.

Important Consideration

A partially transparent flood image is not automatically an overlay on the original graphic. Combining the flood with the source requires additional compositing or merging operations.

Compositing and Transparency

SVG filter compositing allows a flood image to be combined with the original graphic or with other filter results.

Creating a Colored Silhouette

<filter id="colored-silhouette">
  <feflood flood-color="#336699" flood-opacity="0.6" result="color"/>
  <feComposite in="color" in2="SourceAlpha" operator="in"/>
</filter>

The <feComposite> primitive limits the flood image to the alpha shape of the original graphic.

Creating a Colored Shadow

<filter id="soft-shadow" x="-30%" y="-30%" width="160%" height="160%">
  <feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>
  <feOffset in="blur" dx="5" dy="5" result="offsetBlur"/>
  <feflood flood-color="#336699" flood-opacity="0.4" result="shadowColor"/>
  <feComposite in="shadowColor" in2="offsetBlur" operator="in" result="shadow"/>
  <feMerge>
    <feMergeNode in="shadow"/>
    <feMergeNode in="SourceGraphic"/>
  </feMerge>
</filter>

The flood image supplies the shadow color and opacity. The blurred, offset alpha controls the shadow shape, and the final merge places the original graphic above the shadow.

Why Opacity Matters

Lower flood opacity produces a more transparent shadow or overlay, allowing more of the underlying content to remain visible.

Important Consideration

Filter primitive order affects the final result. A later primitive can replace, mask, or combine earlier images.

Using CSS Custom Properties

CSS custom properties allow the same SVG filter structure to use different flood opacity values.

Define a Custom Property

:root {
  --flood-strength: 0.5;
}

Apply the Custom Property

feflood {
  flood-opacity: var(--flood-strength);
}

Create Different Strengths

.effect-light {
  --flood-strength: 0.2;
}
.effect-medium {
  --flood-strength: 0.5;
}
.effect-strong {
  --flood-strength: 0.8;
}

Each SVG container can provide a different custom property value to its descendant <feflood> elements.

Important Consideration

Custom properties follow the CSS cascade. The value must be available where the var() function is evaluated.

Animating flood-opacity

The flood-opacity property can be animated to create gradual changes in the transparency of an SVG flood image.

CSS Transition

feflood {
  flood-opacity: 0.2;
  transition: flood-opacity 0.4s ease;
}
svg:hover feflood {
  flood-opacity: 0.8;
}

When the SVG is hovered, the flood opacity can transition from 0.2 to 0.8.

CSS Keyframes

@keyframes flood-fade {
  from {
    flood-opacity: 0.2;
  }
  to {
    flood-opacity: 0.8;
  }
}
feflood {
  animation: flood-fade 2s ease-in-out infinite alternate;
}

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  feflood {
    animation: none;
    transition: none;
  }
}

The media query disables the animation and transition for users who request reduced motion.

Important Consideration

Animating a filter property may require repeated filter rendering. Test complex effects for performance, especially when many filtered elements are animated simultaneously.

flood-opacity Example

This example compares four opacity values using the same blue flood color. A checkerboard background makes the transparency differences easier to see.

HTML Example

<svg class="flood-opacity-demo" viewBox="0 0 440 150" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Four blue flood rectangles with opacity values of 25, 50, 75, and 100 percent">
  <defs>
    <pattern id="opacity-checker" width="16" height="16" patternUnits="userSpaceOnUse">
      <rect width="16" height="16" fill="#fff"/>
      <rect width="8" height="8" fill="#ddd"/>
      <rect x="8" y="8" width="8" height="8" fill="#ddd"/>
    </pattern>
    <filter id="opacity-25" x="0" y="0" width="1" height="1">
      <feflood flood-color="#336699" flood-opacity="0.25"/>
    </filter>
    <filter id="opacity-50" x="0" y="0" width="1" height="1">
      <feflood flood-color="#336699" flood-opacity="0.5"/>
    </filter>
    <filter id="opacity-75" x="0" y="0" width="1" height="1">
      <feflood flood-color="#336699" flood-opacity="0.75"/>
    </filter>
    <filter id="opacity-100" x="0" y="0" width="1" height="1">
      <feflood flood-color="#336699" flood-opacity="1"/>
    </filter>
  </defs>
  <g>
    <rect x="10" y="10" width="90" height="90" fill="url(#opacity-checker)"/>
    <rect x="120" y="10" width="90" height="90" fill="url(#opacity-checker)"/>
    <rect x="230" y="10" width="90" height="90" fill="url(#opacity-checker)"/>
    <rect x="340" y="10" width="90" height="90" fill="url(#opacity-checker)"/>
  </g>
  <rect x="10" y="10" width="90" height="90" filter="url(#opacity-25)"/>
  <rect x="120" y="10" width="90" height="90" filter="url(#opacity-50)"/>
  <rect x="230" y="10" width="90" height="90" filter="url(#opacity-75)"/>
  <rect x="340" y="10" width="90" height="90" filter="url(#opacity-100)"/>
  <g font-size="14" text-anchor="middle" fill="#333">
    <text x="55" y="125">25%</text>
    <text x="165" y="125">50%</text>
    <text x="275" y="125">75%</text>
    <text x="385" y="125">100%</text>
  </g>
</svg>

CSS Example

.flood-opacity-demo {
  display: block;
  width: 100%;
  max-width: 440px;
  height: auto;
}
Browser Result
25% 50% 75% 100%

All four rectangles use the same flood-color value. Only flood-opacity changes, producing progressively stronger blue flood images.

The checkerboard remains most visible through the 25% flood and is completely covered by the 100% flood.

Common Mistakes

Several common misunderstandings can cause unexpected transparency behavior.

Confusing flood-opacity with opacity

The flood-opacity property controls the flood image produced by <feflood>. The opacity property controls the opacity of a rendered element or group.

Confusing flood-opacity with fill-opacity

The fill-opacity property affects SVG fill painting. It does not control the opacity of a flood filter primitive.

Applying flood-opacity to Ordinary HTML Elements

The property does not make a normal HTML element transparent. Use opacity or an alpha-enabled background color for that purpose.

Ignoring Alpha in flood-color

A flood color can contain its own alpha value. The color alpha and flood-opacity both affect the final transparency.

Expecting the Flood to Blend Automatically

An <feflood> primitive creates a separate image. Additional filter primitives are needed to combine it with the original graphic.

Forgetting to Apply the Filter

A filter definition does not affect rendered content until it is referenced by a graphic or element.

Ignoring the Filter Region

The flood image is generated within its filter primitive region. Incorrect region dimensions can clip or limit the intended effect.

Important Considerations

Keep the following points in mind when using flood-opacity:

  • Purpose: Controls the opacity of an SVG flood filter image.
  • Initial value: 1.
  • Inheritance: The property is inherited.
  • Applies to: SVG <feflood> elements.
  • Numeric values: Accepts numbers such as 0, 0.5, and 1.
  • Percentage values: Accepts percentages such as 25% and 75%.
  • Zero: Produces a fully transparent flood image.
  • One: Applies no additional transparency to the flood color.
  • Intermediate values: Produce partially transparent flood images.
  • Out-of-range values: Are clamped to the valid opacity range for rendering.
  • flood-color: Specifies the color used by the flood primitive.
  • Color alpha: Combines with flood opacity to determine final transparency.
  • SVG presentation attribute: The flood-opacity attribute can also specify the property.
  • CSS cascade: CSS declarations can override SVG presentation attributes.
  • Filter region: Determines where the flood image is generated.
  • Compositing: Combines the flood image with other filter results.
  • SourceAlpha: Can be used to limit a flood image to the original graphic's alpha shape.
  • Custom properties: Allow reusable opacity values.
  • Animation: Supports gradual opacity changes.
  • Performance: Complex animated filters may require additional rendering work.
  • Browser compatibility: Basic SVG flood effects are broadly supported in modern browsers.
  • Distinct from opacity: Does not directly control the overall opacity of an HTML or SVG element.
  • Distinct from fill-opacity: Does not directly control SVG shape fill opacity.

Use flood-opacity when an SVG filter needs precise control over the transparency of a generated flood image. Combine it with flood-color and other filter primitives to create transparent overlays, colored shadows, and similar graphical effects.

Browser Support

The CSS flood-opacity property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari, for SVG flood filter effects.

Numeric opacity values have broad support. Percentage syntax is part of the modern property definition, but numeric values may provide better compatibility with older SVG implementations.

Supported Example

feflood {
  flood-opacity: 0.5;
}

SVG Presentation Attribute

<feflood flood-color="#336699" flood-opacity="0.5"/>

Feature Detection

@supports (flood-opacity: 0.5) {
  feflood {
    flood-opacity: 0.5;
  }
}

The @supports rule checks whether the browser recognizes the CSS declaration. It does not guarantee identical rendering for every SVG filter chain.

Compatibility Considerations

When supporting older browsers, use numeric opacity values and test the complete SVG filter effect. Rendering differences may also result from compositing, filter regions, and color interpolation.

For current compatibility information, visit Can I Use? and search for flood-opacity or SVG filters.

Specifications

The flood-opacity property is defined in the Filter Effects Module Level 1, which describes SVG filter primitives and their rendering behavior.

Filter Effects Module Level 1: flood-opacity Property

The specification also defines the <feflood> primitive and explains how flood color and opacity contribute to the generated filter image.

Filter Effects Module Level 1: feflood Element

For related color and alpha behavior, see the CSS Color Module.

CSS Color Module Level 4