CSS lighting-color Property
The CSS lighting-color property specifies the color of the light source used by SVG diffuse and specular lighting filter primitives.
It applies to the SVG <fediffuselighting> and <feSpecularLighting> elements. By changing the light color, you can create warm, cool, or colored lighting effects on SVG graphics and filtered HTML elements.
lighting-color Syntax
The lighting-color property accepts a CSS color value.
Basic Syntax
selector {
lighting-color: white;
}
Named Color
fediffuselighting {
lighting-color: gold;
}
Hexadecimal Color
fediffuselighting {
lighting-color: #ffcc66;
}
RGB Color
feSpecularLighting {
lighting-color: rgb(100 180 255);
}
HSL Color
fediffuselighting {
lighting-color: hsl(45 100% 70%);
}
Current Color
fediffuselighting {
lighting-color: currentColor;
}
CSS Custom Property
fediffuselighting {
lighting-color: var(--light-color, white);
}
CSS-Wide Keywords
fediffuselighting {
lighting-color: initial;
}
fediffuselighting {
lighting-color: inherit;
}
fediffuselighting {
lighting-color: unset;
}
fediffuselighting {
lighting-color: revert;
}
fediffuselighting {
lighting-color: revert-layer;
}
The initial value is white. Lengths, percentages by themselves, and keywords such as none are not valid values.
Property Values
The property accepts CSS colors and CSS-wide keywords.
| Value | Description |
|---|---|
<color> |
Specifies the color used by the SVG lighting calculation. |
white |
Uses white light and is the initial value. |
| Named colors | Uses a CSS color keyword such as gold, cyan, or tomato. |
| Hexadecimal colors | Uses hexadecimal color notation such as #ffcc66. |
rgb() |
Defines the color using red, green, and blue components. |
hsl() |
Defines the color using hue, saturation, and lightness. |
currentColor |
Uses the element's computed color value. |
transparent |
Specifies a fully transparent color, producing no visible light contribution from that color. |
initial |
Resets the property to white. |
inherit |
Uses the computed value from the parent element. |
unset |
Uses the inherited value because the property is inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | white |
| Inherited | Yes |
| Applies to | <fediffuselighting> and <feSpecularLighting> |
| Computed value | Computed CSS color |
| Animation type | By computed color value |
| Percentages | Only as components of supported color functions |
| Primary use | SVG filter lighting effects |
| Related SVG elements | <fedistantlight>, <fePointLight>, <feSpotLight> |
Although CSS declarations can be written using ordinary selectors, the property has a defined rendering effect on SVG diffuse and specular lighting primitives rather than ordinary HTML text or backgrounds.
How It Works
SVG lighting filters simulate how light interacts with a surface. The surface is represented by height information derived from an input image's alpha channel.
The lighting-color property determines the color of the simulated light. Other SVG filter attributes control the light's direction, position, intensity, and surface response.
Lighting Filter Structure
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="light-effect">
<fediffuselighting lighting-color="gold" surfaceScale="4">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
</filter>
</svg>
The <fediffuselighting> element calculates a diffuse lighting result using gold-colored light.
Changing the Color with CSS
fediffuselighting {
lighting-color: lightblue;
}
The CSS declaration can override a corresponding SVG presentation attribute through the normal cascade.
Important Consideration
The property does not create a light source by itself. A lighting primitive and a suitable SVG light-source element are required to produce a lighting effect.
Default Value
The initial value of lighting-color is white.
Explicit White Light
fediffuselighting {
lighting-color: white;
}
Reset to the Initial Value
feSpecularLighting {
lighting-color: initial;
}
Default SVG Lighting
<fediffuselighting surfaceScale="3">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
If no inherited or explicitly assigned lighting color applies, the filter uses white light.
Important Consideration
White light does not mean the filtered result must appear white. The final appearance also depends on the lighting calculation, the input surface, and any subsequent filter operations.
Named Colors
CSS named colors provide a convenient way to define a lighting color without specifying individual color components.
Warm Light
fediffuselighting {
lighting-color: gold;
}
Cool Light
fediffuselighting {
lighting-color: lightblue;
}
Colored Highlight
feSpecularLighting {
lighting-color: cyan;
}
Red Lighting
feSpecularLighting {
lighting-color: tomato;
}
Important Consideration
Named colors are useful for simple examples. Hexadecimal and functional color notation provide more precise control over the final color.
Hexadecimal Colors
Hexadecimal notation specifies a color using red, green, and blue channel values.
Warm Yellow Light
fediffuselighting {
lighting-color: #ffcc66;
}
Blue Light
fediffuselighting {
lighting-color: #66ccff;
}
Pink Highlight
feSpecularLighting {
lighting-color: #ff66cc;
}
Short Hexadecimal Notation
fediffuselighting {
lighting-color: #fc6;
}
The three-digit notation expands to #ffcc66.
Important Consideration
Hexadecimal notation is useful when matching an established color palette. The rendered lighting effect may not visually match the flat color swatch because lighting calculations also depend on surface geometry and intensity.
RGB Colors
The rgb() function specifies a lighting color using red, green, and blue components.
RGB Light
fediffuselighting {
lighting-color: rgb(255 200 100);
}
Percentage Components
fediffuselighting {
lighting-color: rgb(100% 75% 40%);
}
RGB with Alpha
feSpecularLighting {
lighting-color: rgb(100 180 255 / 70%);
}
The alpha component is part of the CSS color value. The SVG lighting computation uses the applicable color and opacity behavior defined by the filter specification.
Important Consideration
RGB values provide precise color control, but the visible result also depends on the filter's color interpolation and lighting parameters.
HSL Colors
The hsl() function defines a color using hue, saturation, and lightness.
Golden Light
fediffuselighting {
lighting-color: hsl(45 100% 70%);
}
Blue Light
fediffuselighting {
lighting-color: hsl(210 100% 70%);
}
Purple Highlight
feSpecularLighting {
lighting-color: hsl(280 90% 75%);
}
HSL with Alpha
feSpecularLighting {
lighting-color: hsl(200 100% 70% / 80%);
}
Important Consideration
HSL is convenient when experimenting with different hues while maintaining similar saturation and lightness values.
currentColor
The currentColor keyword uses the computed value of the element's color property.
Using currentColor
fediffuselighting {
color: #ffcc66;
lighting-color: currentColor;
}
Inherited Color
svg {
color: lightblue;
}
fediffuselighting {
lighting-color: currentColor;
}
If the lighting primitive inherits the SVG element's text color, currentColor uses that value.
Theme-Based Color
.theme-light {
color: #ffcc66;
}
.theme-light fediffuselighting {
lighting-color: currentColor;
}
Important Consideration
currentColor does not automatically use the fill color of an SVG shape. It refers to the computed CSS color property.
Diffuse Lighting
The SVG <fediffuselighting> filter primitive simulates light scattered from a surface. It produces a lighting result based on the surface orientation relative to the light source.
Diffuse Lighting Filter
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="diffuse-light">
<fediffuselighting in="sourcealpha" surfaceScale="4" diffuseConstant="1" lighting-color="#ffcc66">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
</filter>
</svg>
CSS Lighting Color
#diffuse-light fediffuselighting {
lighting-color: #66ccff;
}
The CSS declaration changes the diffuse light from a warm yellow to a cool blue.
Diffuse Constant
<fediffuselighting diffuseConstant="1.5" surfaceScale="4" lighting-color="white">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
The diffuseConstant attribute affects the intensity of the diffuse lighting calculation.
Important Consideration
Diffuse lighting produces a calculated light image. To combine it with the original graphic, use additional filter primitives such as <fecomposite> or <feBlend>.
Specular Lighting
The SVG <feSpecularLighting> filter primitive simulates reflective highlights on a surface.
Specular Lighting Filter
<svg xmlns="http://www.w3.org/2000/svg">
<filter id="specular-light">
<feSpecularLighting in="sourcealpha" surfaceScale="4" specularConstant="1" specularExponent="20" lighting-color="white">
<fePointLight x="80" y="30" z="100" />
</feSpecularLighting>
</filter>
</svg>
Colored Highlight
#specular-light feSpecularLighting {
lighting-color: #66ccff;
}
Specular Constant
<feSpecularLighting specularConstant="1.5" specularExponent="20" lighting-color="white">
<fePointLight x="80" y="30" z="100" />
</feSpecularLighting>
The specularConstant attribute affects highlight intensity.
Specular Exponent
<feSpecularLighting specularExponent="40" lighting-color="white">
<fePointLight x="80" y="30" z="100" />
</feSpecularLighting>
The specularExponent attribute affects the concentration of the highlight.
Important Consideration
Specular lighting is useful for glossy highlights, metallic appearances, and raised-surface effects. The final result depends on the light source and surface geometry, not only the light color.
SVG Light Sources
SVG provides three light-source elements for diffuse and specular lighting filters.
| Element | Description |
|---|---|
<fedistantlight> |
Simulates light coming from a distant source with a consistent direction. |
<fePointLight> |
Simulates light emitted from a specific point in three-dimensional space. |
<feSpotLight> |
Simulates a directional spotlight aimed at a target position. |
Distant Light
<fediffuselighting lighting-color="gold">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
Point Light
<fediffuselighting lighting-color="lightblue">
<fePointLight x="100" y="50" z="150" />
</fediffuselighting>
Spotlight
<feSpecularLighting lighting-color="white">
<feSpotLight x="100" y="20" z="150" pointsAtX="100" pointsAtY="100" pointsAtZ="0" limitingConeAngle="30" />
</feSpecularLighting>
Important Consideration
The light-source elements determine the direction and location of the light. The lighting-color property belongs on the parent lighting primitive, not on the light-source child.
Applying SVG Filters
SVG lighting filters can be applied to SVG graphics or HTML elements using the CSS filter property.
Define the SVG Filter
<svg width="0" height="0" aria-hidden="true">
<defs>
<filter id="colored-light">
<fediffuselighting in="sourcealpha" surfaceScale="4" lighting-color="gold" result="light">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
<fecomposite in="light" in2="SourceGraphic" operator="in" />
</filter>
</defs>
</svg>
Apply to an HTML Element
.filtered-element {
filter: url(#colored-light);
}
Apply to an SVG Shape
<rect x="20" y="20" width="160" height="100" fill="#2563eb" filter="url(#colored-light)" />
Important Consideration
The CSS filter property applies the complete SVG filter. The lighting-color property controls only the light color within the lighting primitive.
CSS Property vs. SVG Attribute
The light color can be specified using the SVG lighting-color presentation attribute or the corresponding CSS property.
SVG Presentation Attribute
<fediffuselighting lighting-color="gold">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
CSS Property
fediffuselighting {
lighting-color: gold;
}
Class-Based Styling
<fediffuselighting class="warm-light">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
.warm-light {
lighting-color: #ffcc66;
}
CSS Overrides the Presentation Attribute
<fediffuselighting class="custom-light" lighting-color="white">
<fedistantlight azimuth="225" elevation="45" />
</fediffuselighting>
.custom-light {
lighting-color: gold;
}
The CSS declaration takes precedence over the presentation attribute under the normal cascade rules.
Important Consideration
Presentation attributes are convenient for self-contained SVG graphics. CSS rules are useful when several filters share a color scheme or when the color needs to change dynamically.
Color Interpolation
SVG lighting calculations are affected by the color space used for filter processing.
Linear RGB Processing
fediffuselighting {
lighting-color: #ffcc66;
color-interpolation-filters: linearRGB;
}
sRGB Processing
fediffuselighting {
lighting-color: #ffcc66;
color-interpolation-filters: sRGB;
}
Color Space Comparison
The linearRGB and sRGB settings can produce different lighting results because they use different representations for color calculations.
Important Consideration
The default filter color interpolation is generally linearRGB. When exact color appearance matters, test the complete filter and specify color-interpolation-filters where appropriate.
Custom Properties
CSS custom properties allow a lighting color to be reused and changed without editing every filter declaration.
Define a Lighting Color
:root {
--light-color: #ffcc66;
}
fediffuselighting {
lighting-color: var(--light-color);
}
Fallback Color
fediffuselighting {
lighting-color: var(--light-color, white);
}
Theme Variations
.warm-theme {
--light-color: #ffcc66;
}
.cool-theme {
--light-color: #66ccff;
}
fediffuselighting {
lighting-color: var(--light-color, white);
}
Important Consideration
Custom properties follow the CSS cascade and inheritance rules. Define them on an ancestor of the SVG lighting primitive when the value needs to be inherited.
Inheritance
The lighting-color property is inherited. A lighting primitive can receive its value from an ancestor unless it specifies another value.
Inherited Lighting Color
svg {
lighting-color: gold;
}
Descendant lighting primitives can inherit the specified color.
Override Inherited Color
svg {
lighting-color: gold;
}
feSpecularLighting {
lighting-color: lightblue;
}
Explicit Inheritance
fediffuselighting {
lighting-color: inherit;
}
Reset to White
fediffuselighting {
lighting-color: initial;
}
Using unset
fediffuselighting {
lighting-color: unset;
}
Because the property is inherited, unset behaves like inherit.
Important Consideration
Inheritance can simplify shared SVG styling, but it is important to check which ancestor supplies the computed value.
lighting-color Example
This example uses SVG diffuse lighting to compare warm, cool, and neutral light colors. Each filter applies a different lighting color to the same raised surface.
HTML Example
<div class="lighting-demo">
<svg viewBox="0 0 540 170" role="img" aria-label="Three raised rectangles with warm, cool, and white lighting">
<defs>
<filter id="warm-light" x="-20%" y="-20%" width="140%" height="140%">
<fegaussianblur in="sourcealpha" stddeviation="3" result="surface" />
<fediffuselighting in="surface" surfaceScale="5" lighting-color="#ffcc66" result="light">
<fedistantlight azimuth="225" elevation="50" />
</fediffuselighting>
<fecomposite in="light" in2="sourcealpha" operator="in" />
</filter>
<filter id="cool-light" x="-20%" y="-20%" width="140%" height="140%">
<fegaussianblur in="sourcealpha" stddeviation="3" result="surface" />
<fediffuselighting in="surface" surfaceScale="5" lighting-color="#66ccff" result="light">
<fedistantlight azimuth="225" elevation="50" />
</fediffuselighting>
<fecomposite in="light" in2="sourcealpha" operator="in" />
</filter>
<filter id="white-light" x="-20%" y="-20%" width="140%" height="140%">
<fegaussianblur in="sourcealpha" stddeviation="3" result="surface" />
<fediffuselighting in="surface" surfaceScale="5" lighting-color="white" result="light">
<fedistantlight azimuth="225" elevation="50" />
</fediffuselighting>
<fecomposite in="light" in2="sourcealpha" operator="in" />
</filter>
</defs>
<rect x="25" y="25" width="140" height="95" rx="12" fill="#888" filter="url(#warm-light)" />
<rect x="200" y="25" width="140" height="95" rx="12" fill="#888" filter="url(#cool-light)" />
<rect x="375" y="25" width="140" height="95" rx="12" fill="#888" filter="url(#white-light)" />
<text x="95" y="160" text-anchor="middle">Warm Light</text>
<text x="270" y="160" text-anchor="middle">Cool Light</text>
<text x="445" y="160" text-anchor="middle">White Light</text>
</svg>
</div>
CSS Example
.lighting-demo {
padding: 15px;
border: 1px solid #d1d5db;
background-color: #f8fafc;
}
.lighting-demo svg {
display: block;
width: 100%;
height: auto;
}
.lighting-demo text {
fill: #334155;
font-family: Arial, sans-serif;
font-size: 14px;
font-weight: 600;
}
The three examples use the same surface and lighting direction. Only the lighting-color value changes, demonstrating how the light color affects the filtered result.
Change the Warm Light
#warm-light fediffuselighting {
lighting-color: tomato;
}
Change the Cool Light
#cool-light fediffuselighting {
lighting-color: violet;
}
Try different colors to compare how the simulated lighting changes while the surface and light direction remain the same.
Common Mistakes
Applying lighting-color to Ordinary HTML Elements
.box {
lighting-color: gold;
}
This does not directly change the appearance of a normal HTML box. The property is intended for SVG diffuse and specular lighting primitives.
Confusing lighting-color with color
The color property controls text color and supplies the value for currentColor. The lighting-color property controls the color used in SVG lighting calculations.
Confusing lighting-color with flood-color
The flood-color property specifies the color used by the SVG <feFlood> primitive. It does not define the color of an SVG lighting source.
Forgetting the Light Source
A diffuse or specular lighting primitive needs an appropriate light-source element to define the light direction or position.
Applying the Property to the Light-Source Element
fedistantlight {
lighting-color: gold;
}
The light color belongs on <fediffuselighting> or <feSpecularLighting>, not on <fedistantlight>.
Forgetting to Apply the Filter
Defining an SVG filter does not automatically apply it to a graphic. Reference the filter using the CSS filter property or an SVG filter attribute.
Using Invalid Values
fediffuselighting {
lighting-color: 20px;
}
Length values are invalid because the property expects a CSS color.
Expecting the Light Color to Replace the Original Fill
The lighting primitive generates a lighting image. The final visible result depends on how that image is combined with the source graphic.
Ignoring Filter Color Interpolation
Color interpolation settings can affect the rendered result. Test the complete filter when precise visual output is required.
Important Considerations
Keep the following points in mind when using lighting-color:
- The property specifies the color used by SVG lighting calculations.
- The initial value is
white. - The property is inherited.
- It applies to
<fediffuselighting>and<feSpecularLighting>. - It does not directly style ordinary HTML backgrounds or text.
- It accepts valid CSS color values.
- Named colors, hexadecimal colors, RGB, and HSL notation can be used.
currentColoruses the computed CSScolorvalue.- CSS custom properties can supply reusable lighting colors.
- Diffuse lighting simulates light scattered from a surface.
- Specular lighting simulates reflective highlights.
- SVG light-source elements determine light direction and position.
<fedistantlight>represents directional light from a distant source.<fePointLight>represents light emitted from a point.<feSpotLight>represents a directional spotlight.- The light-source elements do not themselves use
lighting-colorto define the light color. - Surface geometry and lighting parameters influence the final appearance.
- Lighting filter results can be combined with source graphics using other SVG filter primitives.
- SVG filters can be applied to HTML elements using
filter: url(#id). - The property can be specified as a CSS declaration or SVG presentation attribute.
- CSS declarations participate in the cascade and can override presentation attributes.
- Filter color interpolation can affect the final result.
- The property supports color interpolation for animations.
- Complex SVG filters may require additional rendering work.
- Test lighting effects with the intended browser, source graphic, and background.
Browser Support
The CSS lighting-color property has long-established support in modern browsers as part of SVG filter rendering, including Chrome, Edge, Firefox, Safari, and Opera.
Support for individual CSS color functions and advanced SVG filter behavior may vary. Basic named, hexadecimal, RGB, and HSL lighting colors are broadly supported.
For current compatibility information, visit Can I Use? and search for lighting-color.
Specifications
The lighting-color property is defined in the Filter Effects Module Level 1 specification.
Filter Effects Module Level 1: lighting-color
The specification describes the lighting color property and its use with diffuse and specular lighting filter primitives.
For additional documentation and examples, consult MDN Web Docs.
