liveBook · Manning

Blending mode

As explained in Math for Web Design

A blend mode is a rule that mathematically combines source and backdrop color channels to produce a composited color.

A blending mode is a rule for combining the color channels of a source layer with those of a backdrop. Instead of simply painting the source over what is behind it, the browser applies a mathematical recipe at every overlapping pixel. This makes effects such as darkening, lightening, tinting, and layered textures predictable rather than mysterious. section 7.6 section 7.6.1

The browser performs blend calculations with normalized channel values from 0 to 1. It converts ordinary RGB values from 0–255 into that range, applies the selected formula, and converts the result back for display. Multiply multiplies corresponding color values and therefore darkens; screen produces the opposite kind of visual result by lightening. section 7.6.1 section 7.8

Choose the CSS property according to the layers you want to combine:

  • Use mix-blend-mode when an element’s content should blend with its parent background or other overlapping elements. For example, darken can make an image behave like it is viewed through a colored lens. section 7.6.3
  • Use background-blend-mode when multiple background images or a background color should blend within one element before its content is drawn. section 7.6.3
  • Remember that an element using a blend mode creates a new stacking context and blends against the parent stacking context’s backdrop. section 7.6.1

Blend an image with a red background

Set the container background to red and apply mix-blend-mode: darken to the image. In overlapping regions, the darker channel values remain visible, producing a dark red lens-like effect. section 7.6.3

Listing 7.11 Using mix-blend-mode
HTML:
<div class="container">
    <img src="pink-flamingo.png" alt="Photo" class="blended-image">
</div>

CSS:
.container {
    background-color: rgb(255, 0, 0);
}
.blended-image {
    mix-blend-mode: darken;
}

Inspect the complete HTML and CSS listing for an image using mix-blend-mode: darken against a red container. section 7.6.3

How Math for Web Design covers it

How deep it goes
Explains normalized channel calculations, pixel overlap, stacking contexts, and CSS properties, while leaving individual mode formulas largely summarized.
Examples
Demonstrates darken on an image over red and layered background blending with multiply and screen.
What it assumes
Assumes basic CSS colors and overlapping elements while teaching the underlying normalized color calculation from the beginning.
What you can do after
Apply it via CSS using mix-blend-mode or background-blend-mode and predict whether common modes darken or lighten layers.
How it connects
Connects blending modes with CSS colors, opacity, alpha compositing, backgrounds, and stacking contexts.

Also explained in

Compare how 2 books explain blending mode →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.