Blend modes for background images

Two CSS properties share the words blend mode, and they sound like one feature. They mix completely different things, and mixing them up explains most of the odd results.

7 min read
Blend modes for background images
In short
  • background-blend-mode mixes layers inside one element's own background, nothing else on the page.
  • mix-blend-mode mixes a whole element with everything already painted behind it, including siblings.
  • There are 16 standard blend mode keywords, shared by both properties and by SVG and canvas.
  • isolation: isolate stops mix-blend-mode from reaching further back than you intended.
16Standard CSS blend mode keywords
2Blend-mode properties: background and mix
normalDefault value for both properties

One name, two different jobs

CSS has two properties with blend mode in the name, and they solve different problems. background-blend-mode blends the layers inside a single element's background. mix-blend-mode blends the whole element, content included, with whatever is painted behind it in the page.

Both take the same set of keywords, because both are built on the CSS Compositing and Blending specification. The keyword list is also used by SVG and by the canvas globalCompositeOperation property, so the modes behave the same way across the platform.

PropertyWhat it blendsScope
background-blend-modeBackground images, gradients and the background color of one elementStays inside the element
mix-blend-modeThe element itself against the content behind itCan reach parents and siblings

Mixing the two up is the most common source of confusion. If a texture will not blend with the color sitting right next to it, check which property you actually set.

What background-blend-mode mixes

background-blend-mode works on the layers listed in background-image and background-color for one element. A texture such as the concrete wall grunge set can sit under a flat color, and the two blend together with no second element and no script.

.panel {
  background-color: #1f3b73;
  background-image: url("concrete-wall.jpg");
  background-blend-mode: multiply;
}

The property accepts a comma separated list, matched by index to the background layers. If the list is shorter than the number of backgrounds, the last value repeats for the rest. If your markup already stacks a gradient over a photo for readability, as covered in the CSS background-image guide, blend mode applies to that stack too, so a multiply gradient both darkens the image and tints it in one rule.

Concrete wall grunge set, original variant

What mix-blend-mode mixes

mix-blend-mode blends the element it is set on, including its text and borders, with the content painted behind it: a parent's background, a sibling earlier in the paint order, or an image elsewhere on the page.

Reach for this property when text or a shape needs to react to whatever sits under it, not only to its own background.

.badge {
  background: #ffce45;
  mix-blend-mode: difference;
}

Because the element blends with everything behind it in paint order, the result depends on page structure, not only on the element's own styles. Move the badge over a different part of a denim fabric texture and the blended color changes, even though nothing on the badge itself changed.

The 16 blend mode keywords

Both properties share the same keyword set, defined by the CSS Compositing and Blending Level 1 specification. normal is the initial value for each.

GroupKeywords
Darkenmultiply, darken, color-burn
Lightenscreen, lighten, color-dodge
Contrastoverlay, soft-light, hard-light
Comparativedifference, exclusion
Componenthue, saturation, color, luminosity

Together with normal, that is 16 keywords. multiply and screen cover most texture work: multiply darkens and tints, useful for stamping a brand color onto a light texture like kraft paper texture. screen lightens, useful over dark photography. overlay and soft-light raise contrast while keeping both the color and the texture visible, which suits subtle grain work. hard-light behaves like a stronger version of overlay and can push midtones toward full black or white quickly, so it needs a lighter touch.

The comparative modes, difference and exclusion, invert colors based on how far apart they are, which produces strong, often unpredictable results, better suited to graphic effects than to subtle tinting. The component modes, hue, saturation, color and luminosity, take one channel from the top layer and the rest from what sits underneath. color is the most useful of the four for texture work, since it replaces hue and saturation while keeping the underlying image's lightness, which recolors a texture fully while preserving its shading.

Kraft paper texture, cool variant

Keeping mix-blend-mode contained with isolation

mix-blend-mode does not stop at the parent element by default. It keeps compositing backward through the stacking context until it runs out of layers, which can blend an element with something several levels up the tree that you never meant to involve.

The isolation property fixes this. Setting isolation: isolate on a parent creates a new stacking context, so a child with mix-blend-mode only blends with siblings inside that parent and stops there.

.card {
  isolation: isolate;
  background: #0b1b33;
}
.card .highlight {
  mix-blend-mode: screen;
}

Add isolation as soon as a blended element sits inside any component that might later be placed over a different background. Without it, the component looks right while you build it and wrong the first time someone reuses it on a different page.

Debugging a blend that looks wrong

Most blend problems trace back to one of a small number of causes, and checking them in order is faster than trying every keyword at random.

  • Wrong property. Confirm whether the element has its own background color and image, or whether it is sitting over something else. That decides which of the two properties you need.
  • Transparent instead of blended. If a background layer has no color behind it, some modes, such as multiply, blend against the page's default white or the surrounding content in ways that look washed out. Add an explicit background color, even if it is the same tone the page already shows, so the blend has something solid to work against.
  • Order matters. With several layers, modes line up with images by position in the comma separated list. A mode meant for the photo but written for the gradient slot will not do what you expect.
  • Isolation missing. For mix-blend-mode, an unexpected result that changes when you move the element to a different part of the page usually means it is blending with more than you intended. Add isolation on the nearest container and check again.

Checking the rendered result at the actual page zoom level matters too. Some blend results shift slightly depending on how the browser rounds color values during compositing, though this is rarely visible at normal reading distance.

A tinting recipe for the backgrounds on this site

Every file here is a plain JPG with no built in color treatment, which makes blend mode a fast way to match a texture to a brand palette without editing the image.

  1. Pick a neutral or light texture, such as brushed metal texture or a light wood set.
  2. Set the texture as background-image and your brand color as background-color.
  3. Start with background-blend-mode: multiply for a darker tint, or screen for a lighter one.
  4. Lower the color's alpha channel if the first result is too strong, instead of switching modes again.

This keeps one JPG useful across several color variants of a page, instead of exporting a new file for every brand color.

Readability and performance

Blending changes the final color, so check text contrast against the blended result, not against the texture or the color alone. The guide to text contrast on backgrounds covers measuring contrast against the busiest area of an image, and a blend only adds another variable to that same check.

Both properties are compositing operations the browser already performs for every paint, so the ongoing cost is small. One thing to avoid is animating mix-blend-mode directly: each change recomputes the blend rather than interpolating it the way color or opacity transitions do, so motion looks stepped instead of smooth.

If a blended element looks right at the top of the page and wrong once it scrolls behind a different section, it is not isolated and is blending with content you did not plan for.

Questions

What is the difference between background-blend-mode and mix-blend-mode?

background-blend-mode mixes the image, gradient and color layers inside one element's own background. mix-blend-mode mixes the whole element, including its content, with whatever is painted behind it elsewhere on the page.

How many blend mode keywords are there?

The CSS Compositing and Blending specification defines 16 keywords, including normal. The same set is shared by background-blend-mode, mix-blend-mode, SVG and the canvas globalCompositeOperation property.

Why does my mix-blend-mode element blend with the wrong background?

By default it keeps blending backward through the stacking context until it runs out of layers. Set isolation: isolate on a containing element to stop the blend at that boundary.

Does background-blend-mode work with gradients?

Yes. A gradient is a CSS image value, so it takes part in background-blend-mode the same way a photo does. Stacking a gradient over a photo and setting multiply both darkens the photo and tints it in a single rule.

Keep reading

Built for the web.
Free to download.