
CSS scroll-behavior: Smooth Scrolling Between Anchors
05/05/2024
CSS hyphens: Break Long Words at Line Endings
07/05/2024
CSS blend modes control how the colors of an element combine with colors behind it. The backdrop might be a solid color, a photograph, a gradient, or another layer.
This lesson explains the available modes and how to use them in practical examples.
1. What are CSS blend modes?
The mix-blend-mode property blends an element’s rendered content with its backdrop. Different modes can darken, lighten, or adjust the contrast of the result.
Change the layers, opacity, and blend mode to compare how they interact.
2. Blend modes and their visual effects
The table lists common values for mix-blend-mode and describes their effects.
| Blend Mode | Description | Characteristics |
|---|---|---|
| multiply | Multiplies the top and bottom layer colors. | – Darkens the result. |
| screen | Inverts both color inputs, multiplies them, and inverts the result. | – Lightens the result. |
| overlay | Combines multiply and screen according to the backdrop color. | – Can increase contrast and saturation in the result. |
| darken | Keeps the darker value of each color channel. | – Compares the two layers channel by channel. |
| lighten | Keeps the lighter value of each color channel. | – Compares the two layers channel by channel. |
| color-dodge | Brightens the backdrop based on the source color. | – Lightens portions of the backdrop. |
| color-burn | Darkens the backdrop based on the source color. | – Darkens portions of the backdrop. |
| difference | Takes the absolute difference between the two colors in each channel. | – White inverts the backdrop, while black leaves it unchanged. |
| exclusion | Similar to difference, with lower contrast. | – Produces a softer difference effect. |
| hard-light | Combines multiply and screen based on the source color. | – Can produce strong contrast. |
| soft-light | Similar to hard light, with a gentler effect. | – Produces a softer change in contrast. |
| hue | Keeps the backdrop’s luminosity and saturation and uses the source hue. | – Applies the source hue to the backdrop. |
| saturation | Keeps the backdrop’s luminosity and hue and uses the source saturation. | – Applies the source saturation to the backdrop. |
| color | Keeps the backdrop’s luminosity and uses the source hue and saturation. | – Applies the source hue and saturation to the backdrop. |
| luminosity | Keeps the backdrop’s hue and saturation and uses the source luminosity. | – Applies the source luminosity to the backdrop. |
3. Use a blend mode in CSS
Set mix-blend-mode on the element you want to blend with the layers behind it.
Syntax:
.overlay-container {
mix-blend-mode: <blend-mode>;
}
Replace <blend-mode> with a keyword such as multiply, screen, or overlay.
Example:
Use multiply to blend text with the background beneath it.
.overlay-text {
mix-blend-mode: multiply;
}
A visible result needs overlapping colors. For example, put text or a shape over a colored background or an image.
<div class="background-container">
<!-- Add a background image or color here -->
<div class="overlay-container">
<p class="overlay-text">This text blends with the backdrop using multiply.</p>
</div>
</div>
Apply the property to the element that should blend. Its backdrop depends on the stacking context. Use isolation: isolate when you want to confine blending to a particular group.
Visual comparison in CodePen
The first container shows the image without blending. The second uses the same image with multiply.
Change the value on .blend-mode to screen, overlay, lighten, or darken and compare the results.
Try changing the background color too. The result depends on the colors of both layers.
4. Browser support for mix-blend-mode
Check support for mix-blend-mode in the browsers your project targets.
Test the actual colors, text contrast, and layering across browsers. Provide readable text and a useful baseline design if blending is unavailable.
5. Differences between blend modes and CSS filters
Blend modes combine colors across overlapping layers. A CSS filter changes the rendering of the element it is applied to, for example by blurring it or adjusting saturation.
- Blend modes: Control how overlapping layers combine.
- Filters: Apply effects to an element’s rendered output.
Use blending when the result should depend on what sits behind the element. Use a filter when modifying the element itself. See the CSS filters lesson.
6. Practical blend mode examples
Try the examples below to see how text, color, and images can be combined.
6.1. Text effects with overlay
Set overlay on text placed over a background image. Test contrast across the entire area the text covers.
CSS:
mix-blend-mode: overlay;
Try it in CodePen:
6.2. Blend a color with a background image using color-dodge
The demo places a red layer at 70% opacity over a background image. The layer uses color-dodge to combine its red color with the image below.
CSS:
mix-blend-mode: color-dodge;
Try it in CodePen:
6.3. Other effects
- Highlight interactive elements: Try
screenon a hover layer while keeping a readable baseline and a visible focus style. - Layer images: Try
multiplyorsoft-lightwhere two layers overlap. - Add depth: Use
multiplyon a shadow layer to blend the shadow with a background. - Combine gradients: Experiment with different modes on overlapping gradients to change the resulting colors.
Change the colors, layers, and values in the demos to see which combinations work for your own project.