CSS flood-color Property
The flood-color property specifies the color used by the SVG <feflood> filter primitive to fill its filter region with a uniform color.
This property is used in SVG filter effects, often to create colored shadows, overlays, highlights, and other graphical effects. It works with flood-opacity to control the color and transparency of the generated flood image.
flood-color Syntax
The flood-color property accepts a CSS color value. The selected color is used when an SVG <feflood> filter primitive generates its flood image.
Basic Syntax
selector {
flood-color: blue;
}
Common Color Values
.flood-one {
flood-color: red;
}
.flood-two {
flood-color: #336699;
}
.flood-three {
flood-color: rgb(51 102 153);
}
.flood-four {
flood-color: hsl(210 50% 40%);
}
.flood-five {
flood-color: currentColor;
}
CSS-Wide Keywords
.flood {
flood-color: inherit;
}
.flood {
flood-color: initial;
}
.flood {
flood-color: unset;
}
.flood {
flood-color: revert;
}
.flood {
flood-color: revert-layer;
}
The initial value is black. The property is inherited, so an <feflood> element can receive its flood color from an ancestor.
Property Values
The flood-color property supports CSS color values, including named colors, hexadecimal notation, functional color notation, and currentColor.
| Value | Description |
|---|---|
| Named color | Uses a predefined CSS color keyword, such as red, blue, or rebeccapurple. |
| Hexadecimal color | Uses hexadecimal notation, such as #336699 or #369. |
rgb() |
Defines the color using red, green, and blue components. |
hsl() |
Defines the color using hue, saturation, and lightness. |
hwb() |
Defines the color using hue, whiteness, and blackness. |
lab(), lch(), and related functions |
Define colors using supported modern CSS color spaces. |
currentColor |
Uses the computed value of the element's color property. |
transparent |
Specifies a fully transparent color. |
CSS-Wide Values
| Value | Description |
|---|---|
inherit |
Uses the computed flood-color value of the parent element. |
initial |
Restores the initial value, black. |
unset |
Uses the inherited value because flood-color is an inherited property. |
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 | black |
| Inherited | Yes |
| Applies to | <feflood> elements |
| Computed value | Computed color |
| Animation type | By computed color |
| Percentages | Not applicable to the property itself |
The property affects the color produced by an SVG flood filter. It does not change an element's normal background, text color, or SVG fill paint.
How It Works
The SVG <feflood> primitive creates an image filled with a uniform color. The flood-color property determines that color, while flood-opacity controls its opacity.
Step 1: Define an SVG Filter
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<filter id="color-flood">
<feflood flood-color="#336699" result="flood"/>
</filter>
</defs>
</svg>
Step 2: Apply the Filter
<rect x="10" y="10" width="160" height="80" filter="url(#color-flood)"/>
The filter generates a blue flood image. When the flood primitive is the filter's final output, it replaces the filtered element's appearance within the filter region.
Step 3: Control the Color with CSS
feflood {
flood-color: #336699;
}
The CSS declaration sets the flood color for matching SVG <feflood> elements.
Step 4: Adjust Transparency
feflood {
flood-color: #336699;
flood-opacity: 0.5;
}
The filter now generates a semi-transparent blue flood image.
Important Distinction
The flood image is a filter input or output. It does not automatically blend with the original graphic. To combine the flood color with the original content, additional filter primitives such as <feComposite> or <feMerge> are needed.
Named Colors
Named CSS colors provide a simple way to specify flood colors without using numeric color components.
Syntax
feflood {
flood-color: steelblue;
}
Examples
.flood-red {
flood-color: red;
}
.flood-green {
flood-color: seagreen;
}
.flood-blue {
flood-color: royalblue;
}
.flood-purple {
flood-color: rebeccapurple;
}
Using SVG Attributes
<feflood flood-color="steelblue"/>
The flood-color presentation attribute provides another way to set the color directly in SVG markup.
Important Consideration
CSS declarations generally take precedence over corresponding SVG presentation attributes when both specify the same property on an element.
Hexadecimal Colors
Hexadecimal color notation provides precise control over red, green, and blue components.
Six-Digit Hexadecimal Color
feflood {
flood-color: #336699;
}
Three-Digit Hexadecimal Color
feflood {
flood-color: #369;
}
The shorthand #369 represents the same RGB color as #336699.
Hexadecimal Color with Alpha
feflood {
flood-color: #33669980;
}
The final two hexadecimal digits represent an alpha component. In this example, the color is approximately 50% opaque.
Important Consideration
Alpha included in the color value and the separate flood-opacity property both contribute to the final transparency of the generated flood image.
Functional Color Values
The flood-color property also accepts supported CSS color functions.
Using rgb()
feflood {
flood-color: rgb(51 102 153);
}
Using hsl()
feflood {
flood-color: hsl(210 50% 40%);
}
Using Alpha Transparency
feflood {
flood-color: rgb(51 102 153 / 50%);
}
Using hwb()
feflood {
flood-color: hwb(210 20% 40%);
}
Using Modern Color Functions
feflood {
flood-color: oklch(55% 0.12 250);
}
Modern CSS color functions provide additional ways to define colors. Browser support for individual color functions can vary, even when the flood-color property itself is supported.
Using currentColor
The currentColor keyword allows the flood color to use the computed value of the element's color property.
CSS Example
.flood-effect {
color: #336699;
}
.flood-effect feflood {
flood-color: currentColor;
}
HTML Example
<svg class="flood-effect" viewBox="0 0 200 100">
<defs>
<filter id="current-color-filter">
<feflood flood-color="currentColor"/>
</filter>
</defs>
<rect x="10" y="10" width="180" height="80" filter="url(#current-color-filter)"/>
</svg>
The <feflood> element can inherit the color value from its SVG ancestors and use that color for the flood image.
Important Consideration
The currentColor keyword refers to the computed color value of the element where it is used. It does not automatically refer to the fill or text color of a separate element that uses the filter.
Working with flood-opacity
The flood-color and flood-opacity properties work together to determine the color and transparency of the flood image.
Fully Opaque Flood
feflood {
flood-color: #336699;
flood-opacity: 1;
}
Semi-Transparent Flood
feflood {
flood-color: #336699;
flood-opacity: 0.5;
}
Fully Transparent Flood
feflood {
flood-color: #336699;
flood-opacity: 0;
}
Color Alpha and Flood Opacity
feflood {
flood-color: rgb(51 102 153 / 50%);
flood-opacity: 0.5;
}
When the color has its own alpha component, the flood opacity is applied in addition to that alpha. In this example, the resulting flood image has approximately 25% opacity.
Important Consideration
The opacity property on an element and the flood-opacity property of an <feflood> primitive serve different purposes. Use flood-opacity to control the flood image itself.
Using flood-color in SVG Filters
SVG filters consist of one or more filter primitives. The <feflood> primitive generates a solid-color image that can be used independently or combined with other filter results.
Basic Flood Filter
<svg viewBox="0 0 220 120" xmlns="http://www.w3.org/2000/svg">
<defs>
<filter id="blue-flood" x="0" y="0" width="1" height="1">
<feflood flood-color="#336699"/>
</filter>
</defs>
<rect x="20" y="20" width="180" height="80" filter="url(#blue-flood)"/>
</svg>
The filter outputs a uniform blue image within its filter region.
Applying CSS to the Filter Primitive
#blue-flood feflood {
flood-color: #336699;
}
Using a Named Filter Result
<filter id="flood-result">
<feflood flood-color="#336699" result="blueFill"/>
<feComposite in="blueFill" in2="SourceAlpha" operator="in"/>
</filter>
The result attribute gives the flood image a name. The following <feComposite> primitive uses that image and the source alpha to produce a colored result shaped by the original graphic.
Important Consideration
The result attribute does not display an intermediate filter image by itself. A later primitive must use that result, or the flood primitive must be the final output of the filter.
Combining Flood Colors with Other Filters
A flood image can be combined with other SVG filter primitives to create effects that depend on the shape or transparency of the original graphic.
Colored Silhouette
<filter id="colored-silhouette">
<feflood flood-color="#336699" result="color"/>
<feComposite in="color" in2="SourceAlpha" operator="in"/>
</filter>
The SourceAlpha input represents the transparency of the original graphic. The composite operation keeps the flood color where the source has alpha coverage.
Colored Shadow
<filter id="colored-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.6" result="shadowColor"/>
<feComposite in="shadowColor" in2="offsetBlur" operator="in" result="shadow"/>
<feMerge>
<feMergeNode in="shadow"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
The source alpha is blurred and offset. The flood color is then limited to that shadow shape and merged behind the original graphic.
Why Compositing Matters
Without compositing, an <feflood> primitive generates a uniform color across its filter primitive region. Compositing allows that color to follow the shape of another filter input.
Important Consideration
Filter primitive order matters. Each primitive can use an earlier result, and the final filter output determines the appearance of the filtered element.
Using CSS Custom Properties
CSS custom properties can make flood colors easier to manage when the same color is used by several SVG filters.
Define a Custom Property
:root {
--filter-color: #336699;
}
Use the Custom Property
feflood {
flood-color: var(--filter-color);
}
Override the Color
.filter-warning {
--filter-color: #cc6633;
}
.filter-success {
--filter-color: #228866;
}
Different SVG containers can provide their own custom property values, allowing the same filter styling rules to produce different colors.
Important Consideration
Custom properties follow the CSS cascade and inheritance rules. The value must be available to the <feflood> element where the var() function is resolved.
flood-color Example
This example demonstrates three SVG rectangles whose colors are generated by separate <feflood> primitives. The flood colors are defined in CSS rather than through inline presentation attributes.
HTML Example
<svg class="flood-demo" viewBox="0 0 360 130" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Three rectangles with blue, orange, and green flood colors">
<defs>
<filter id="flood-blue" x="0" y="0" width="1" height="1">
<feflood class="flood-blue"/>
</filter>
<filter id="flood-orange" x="0" y="0" width="1" height="1">
<feflood class="flood-orange"/>
</filter>
<filter id="flood-green" x="0" y="0" width="1" height="1">
<feflood class="flood-green"/>
</filter>
</defs>
<rect x="10" y="10" width="100" height="80" filter="url(#flood-blue)"/>
<rect x="130" y="10" width="100" height="80" filter="url(#flood-orange)"/>
<rect x="250" y="10" width="100" height="80" filter="url(#flood-green)"/>
<g font-size="13" text-anchor="middle" fill="#333">
<text x="60" y="112">Blue</text>
<text x="180" y="112">Orange</text>
<text x="300" y="112">Green</text>
</g>
</svg>
CSS Example
.flood-demo {
display: block;
width: 100%;
max-width: 360px;
height: auto;
}
.flood-demo .flood-blue {
flood-color: #336699;
}
.flood-demo .flood-orange {
flood-color: #cc6633;
}
.flood-demo .flood-green {
flood-color: #228866;
}
Each rectangle references a different SVG filter. The corresponding <feflood> primitive produces a uniform color, replacing the rectangle's appearance within the filter region.
Changing the CSS flood-color declarations changes the generated colors without modifying the SVG filter structure.
Common Mistakes
Several common misunderstandings can lead to unexpected results when using flood-color.
Confusing flood-color with fill
The fill property controls the paint used to fill SVG shapes. The flood-color property controls the color generated by an <feflood> filter primitive.
Applying flood-color to a Normal HTML Element
The property does not change the background color of an ordinary HTML element. Use background-color for that purpose.
Expecting the Flood to Follow the Original Shape
A flood image is uniform across its filter region. Use <feComposite> with SourceAlpha when the color should follow the original graphic's alpha shape.
Forgetting to Apply the Filter
Defining an SVG filter does not automatically display it. Reference the filter with the filter property or SVG filter attribute.
Confusing flood-opacity with opacity
The flood-opacity property controls the flood image's opacity. The opacity property affects the opacity of a rendered element or group.
Ignoring Filter Primitive Order
Later filter primitives can replace or combine earlier results. Make sure the flood image is connected to the intended final filter output.
Reusing Filter IDs
Filter IDs must be unique within the relevant document. Duplicate IDs can cause references to resolve to an unintended filter.
Important Considerations
Keep the following points in mind when using flood-color:
- Purpose: Sets the color generated by an SVG
<feflood>filter primitive. - Initial value:
black. - Inheritance: The property is inherited.
- Applies to: SVG
<feflood>elements. - Color values: Accepts supported CSS color values.
- Named colors: Can use predefined keywords such as
redandsteelblue. - Hexadecimal colors: Supports standard hexadecimal color notation.
- Functional colors: Supports CSS color functions such as
rgb()andhsl(). - currentColor: Uses the computed
colorvalue of the relevant element. - Transparency: Can be controlled through color alpha and
flood-opacity. - SVG presentation attribute: The
flood-colorattribute can also specify the property. - CSS cascade: CSS declarations can override SVG presentation attributes.
- Filter region: The flood image is generated within the applicable filter primitive region.
- Filter application: A filter must be referenced to affect rendered content.
- Compositing: Other filter primitives can combine flood colors with source graphics.
- SourceAlpha: Can be used to limit a flood color to the original graphic's alpha shape.
- Custom properties: Can provide reusable flood color values.
- Animation: Flood colors can be interpolated as computed colors.
- Browser compatibility: Support for modern color functions may differ from support for the property itself.
- Distinct from fill: Does not directly control the fill paint of SVG shapes.
- Distinct from background-color: Does not directly set an HTML element's background.
Use flood-color when an SVG filter needs to generate a uniform color image. Combine it with flood-opacity and other filter primitives when the effect requires transparency, masking, or compositing with the original graphic.
Browser Support
The CSS flood-color property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari, for SVG flood filter effects.
Basic named colors, hexadecimal colors, and commonly used RGB and HSL color values are broadly supported. More advanced CSS color functions may require separate compatibility checks.
Supported Example
feflood {
flood-color: #336699;
}
SVG Presentation Attribute
<feflood flood-color="#336699"/>
Feature Detection
@supports (flood-color: #336699) {
feflood {
flood-color: #336699;
}
}
The @supports rule checks whether the browser recognizes the declaration. It does not guarantee that every SVG filter combination renders identically across browsers.
Compatibility Considerations
Test complex SVG filter chains, color interpolation, transparency, and newer color functions when consistent rendering is important.
For current compatibility information, visit Can I Use? and search for flood-color or SVG filters.
Specifications
The flood-color property is defined in the Filter Effects Module Level 1, which describes SVG and CSS filtering operations.
Filter Effects Module Level 1: flood-color Property
The specification also defines the <feflood> filter primitive, including how it generates a uniform color image and how the flood opacity is applied.
Filter Effects Module Level 1: feflood Element
For CSS color notation, see the CSS Color Module.
