Skip to content
Tutorials Center
My learning

Topics

Lesson 55 of 139 ยท Backgrounds and Effects

Blend Modes

Mix colors between layers with mix-blend-mode and background-blend-mode, learn what multiply, screen and overlay do, and contain blending with isolation.

Normally, when one thing sits on top of another in CSS, the top layer simply covers the bottom one. If the top layer is semi-transparent, you see a bit of both, but the colors are just averaged. Graphics editors offer a richer choice: blend modes, which decide how the color of each top pixel combines with the color of the pixel underneath. Darken only, lighten only, boost contrast, keep the hue but borrow the brightness, and more.

CSS has the same set of blend modes, in two properties. background-blend-mode mixes an element's own background layers with each other. mix-blend-mode mixes a whole element with whatever is behind it on the page. A third property, isolation, lets you fence blending in. This lesson covers all three, with the handful of modes you will actually use most.

How a blend mode works

Each blend mode is a small formula that takes two colors, the source (the top layer) and the backdrop (what is underneath), and returns a new color. The formula runs separately for every pixel, and for most modes separately on the red, green and blue channels, with each channel treated as a number from 0 (none) to 1 (full).

You do not need the math to use blend modes well, but three ideas explain most of them:

  • Multiply multiplies the two values. Anything times 1 (white) stays the same, anything times 0 (black) becomes black. So white disappears and everything else gets darker, like stacking colored transparencies on a projector.
  • Screen is the opposite: it inverts both colors, multiplies, and inverts again. Black disappears and everything else gets lighter, like shining two projectors onto the same wall.
  • Overlay multiplies the dark parts and screens the light parts of the backdrop, so it adds contrast while keeping the backdrop's light and shadow.

Here is the full list of values, grouped by what they do:

Group Values Effect
Normal normal No blending: the top layer covers the bottom one. The default.
Darken multiply, darken, color-burn The result is never lighter than either layer.
Lighten screen, lighten, color-dodge, plus-lighter The result is never darker than either layer.
Contrast overlay, soft-light, hard-light Darks get darker and lights get lighter.
Inversion difference, exclusion Subtracts one color from the other; white inverts what is below.
Component hue, saturation, color, luminosity Takes some properties (hue, saturation, brightness) from each layer.

plus-lighter simply adds the channel values together and is newer than the rest. It is mostly used for smooth cross-fades in View Transitions. All the others have worked in every major browser for years.

background-blend-mode: mixing background layers

An element can have several background layers, as you saw in Multiple Backgrounds. background-blend-mode decides how each layer blends with the layers below it, including the background-color, which is always the bottom layer.

The easiest way to see it is to put a solid color behind an image and try different modes:

background-blend-mode with a color

With normal, the image covers the blue completely. With multiply, the image is tinted blue and darkened. With luminosity, the image's brightness is kept but its colors come from the blue: an instant duotone-style effect with no image editor. Change #0ea5e9 to another color and see how each tile responds.

If an element has several image layers, you can give background-blend-mode a comma-separated list, one value per layer, in the same order as background-image:

CSS
.hero {
  background:
    linear-gradient(to right, #f97316, #8b5cf6),
    url("texture.svg"),
    #1e293b;
  background-blend-mode: overlay, multiply;
}

Here the gradient blends with overlay over the layers below it, and the texture blends with multiply over the color.

A classic use: tinted hero images. Instead of exporting a darkened, colored version of a photo, set a brand color as background-color and use multiply or luminosity. Change the color in one place and every hero updates.

mix-blend-mode: blending whole elements

mix-blend-mode works on a complete element, including its text, borders and children, and blends it with everything painted behind it: parent backgrounds, sibling elements, images. This is the property for text that inverts over a busy background, or for a colored shape that tints the photo under it.

Blending a heading with the image behind it

White with difference inverts whatever is underneath, so each letter takes the opposite colors of the sky and hills behind it. The cyan circle uses multiply, so it darkens and tints the picture rather than covering it. Try screen, overlay or exclusion on both.

Watch your contrast. Blended text changes color with its background, and parts of it can end up close to the color behind it. Use blending for large decorative headings, not for body text, and check that the text stays readable everywhere it might land. A blend mode that works on one image can fail on another.

isolation: keeping blending contained

Blending with mix-blend-mode reaches down through every layer behind the element, as far as the nearest stacking context. Sometimes that is too far. Imagine a card with blended shapes inside it, sitting on a page with a patterned background. You probably want the shapes to blend with the card only, not with the page.

isolation: isolate creates a new stacking context on an element without any other visual change. Blended children then blend only with things inside that element:

isolation: isolate stops blending at the card

In the first card the dot shows the stripes through it, because the semi-transparent card lets them through and the blend reaches all the way down to the page. In the second card the dot blends only with the card, so it looks solid.

Many other properties create a stacking context too, such as opacity below 1, transform, filter and a z-index on a positioned element, and each of them limits blending in the same way. That is often the explanation when a blend mode "stops working" after you add a transform to a parent. isolation: isolate is simply the cleanest way to ask for the boundary on purpose. You will see the full list of triggers in z-index and Stacking Contexts.

background-blend-mode never needs isolation: it only ever mixes the element's own background layers.

Practical tips

  • Blend modes are not filters. A filter changes an element on its own; a blend mode always needs something underneath to mix with. Over plain white, multiply has no visible effect at all.
  • Images with transparent areas blend only where they have pixels. A transparent PNG logo with multiply over a photo shows just the logo shape.
  • The root background counts. If nothing in the page sets a background, blending happens against the canvas color, usually white, which is why difference text on a "transparent" page often looks simply inverted.
  • Performance is usually fine for a few elements, but blending large animated layers forces extra painting work. Test before using it on something that moves constantly.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which property blends an element's background image with its own background color?

    background-blend-mode mixes an element's background layers, including the background color, with each other.
  2. 2. What happens to white areas of an element with mix-blend-mode: multiply?

    Multiplying a color by white (1) leaves it unchanged, so white areas disappear and only darker colors show.
  3. 3. You want blended shapes inside a card to stop blending with the page behind the card. What do you add to the card?

    isolation: isolate creates a stacking context, and blending never reaches past the nearest stacking context.
  4. 4. Which blend mode makes the result lighter, with black disappearing?

    screen is the lightening counterpart of multiply: black has no effect and everything else gets brighter.

Summary

  • Blend modes decide how a top color combines with the color under it: darken (multiply), lighten (screen), add contrast (overlay), invert (difference) or mix hue and brightness (color, luminosity).
  • background-blend-mode blends an element's background layers, including its background color; give it one value per image layer.
  • mix-blend-mode blends a whole element with everything painted behind it.
  • Blending stops at the nearest stacking context; use isolation: isolate to create that boundary on purpose.
  • Keep blended text large and decorative, and always check contrast.

Next: Clip Paths and Masks โ€” cut elements into shapes and fade them out with gradients.