cross-fade() CSS Function
The cross-fade() function blends two or more images together by percentages, creating a new image.
Description
The cross-fade() CSS function blends two or more images together, producing a new image in which each input is shown at a chosen level of transparency. It is like stacking pictures on top of each other with different opacities, but the result is a single <image> value that can be used in properties such as background-image, without extra elements or pseudo-elements.
In the current specification, each argument is an image (or a color) followed by an optional percentage that sets how much of it shows. If percentages are left out, the remaining amount is shared equally between the images that have none. Colors are treated as solid images, so you can, for example, fade a photo toward black. Because the percentages control the blend directly, cross-fade() can also be animated between states to create smooth transitions between two backgrounds.
Browser support is limited. Chromium-based browsers support only the older prefixed form, -webkit-cross-fade(image1, image2, percentage), in which the percentage is the amount of the second image. Safari supports this older two-image form without a prefix, and Firefox does not support the function at all. Always provide a plain background as a fallback.
.photo {
background-image: url("day.jpg"); /* fallback */
background-image: -webkit-cross-fade(url("day.jpg"), url("night.jpg"), 30%);
background-image: cross-fade(url("day.jpg") 70%, url("night.jpg") 30%);
}
/* Darken an image by fading it with black */
.hero {
background-image: cross-fade(url("hero.jpg") 60%, black);
}
Syntax
cross-fade() = cross-fade( <cf-image># )
<cf-image> = [ <image> | <color> ] && <percentage [0,100]>?
/* Older form supported by browsers */
-webkit-cross-fade( <image>, <image>, <percentage> )
Values
- <image> | <color>An image to blend, or a color, which is treated as a solid-color image.
- <percentage>Optional. How much of that image is used, from 0% to 100%. Images without a percentage share whatever is left over equally. In the older -webkit- form, a single percentage sets the amount of the second image.
Example
Browser Support
The following information will show you the current browser support for the CSS cross-fade() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





