CSS Blend Modes & mix-blend-mode
CSS Blend Modes let you control how an element’s content blends with the background or other elements. Think of it like Photoshop blending layers — you can create creative visual effects without editing images externally.
mix-blend-mode is the main property used to blend an element with the background.
Syntax
selector {
mix-blend-mode: blend-mode;
}
Common blend modes:
normal→ default, no blendingmultiply→ multiplies the colors, darkening the resultscreen→ lightens the resultoverlay→ mix of multiply and screen, preserves highlights & shadowsdarken→ keeps the darker colorlighten→ keeps the lighter colorcolor-dodge/color-burn→ brightens or darkens based on base colorsdifference→ subtracts colors, creating contrastexclusion→ similar to difference but softerhue/saturation/color/luminosity→ affects color properties
Basic Mix-Blend-Mode
In this example, the image colors multiply with the yellow background, creating a darker effect.
<div class="background"></div>
<img src="image.jpg" alt="Blend Mode Example" class="blend-img">
.background {
width: 500px;
height: 300px;
background: yellow;
position: absolute;
}
.blend-img {
width: 500px;
mix-blend-mode: multiply;
position: relative;
}
Overlay Text with Blend Mode
The text blends with the image, creating a dynamic overlay effect.
<div class="container">
<img src="image.jpg" alt="Blend Example">
<h2 class="blend-text">Hello World</h2>
</div>
.container {
position: relative;
width: 400px;
}
.container img {
width: 100%;
}
.blend-text {
position: absolute;
top: 50px;
left: 50px;
font-size: 2rem;
color: white;
mix-blend-mode: screen; /* Blends text with the image */
}
Creative Background Effects
<div class="box red"></div>
<div class="box blue"></div>.box {
width: 200px;
height: 200px;
display: inline-block;
}
.red {
background: red;
}
.blue {
background: blue;
mix-blend-mode: screen;
}
