Create compositional effects by mixing two or more layers, and learn how to isolate an image with a white background in this module on blend modes.
Duotone is a popular color treatment for photography which makes an image look like it is only made up of two contrasting colors: one for highlights and the other for lowlights. How do you do this with CSS though?
What is a blend mode? #
Blend modes are commonly used in design tools such as Photoshop to create a compositional effect by mixing colors from two or more layers. By changing how colors mix, you can achieve really interesting visual effects. You can also use blend modes as a utility, such as isolating an image that has a white background, so it appears to have a transparent background.
You can use most of the blend modes available in a design tool with CSS, using the
mix-blend-mode or the
background-blend-mode properties. The
mix-blend-mode applies blending to a whole element and the
background-blend-mode applies blending to the background of an element.
background-blend-mode when you have multiple backgrounds on an element and want them all to blend into each other.
mix-blend-mode affects the entire element, including its pseudo-elements. One use-case is in the initial example of a duotone image, which has color layers applied to the element through its pseudo-elements.
Blend modes fall into two categories: separable and non-separable. A separable blend mode considers each color component, such as RGB, individually. A non-separable blend mode considers all color components equally.
Browser compatibility #
Separable blend modes #
This is the default blend mode and changes nothing about how an element blends with others.
multiply blend mode is like stacking multiple transparencies on top of each other. White pixels will appear transparent, and black pixels will appear black. Anything in between will multiply its luminosity (light) values. This means lights get much lighter and darks, darker—most often producing a darker result.
screen multiplies the light values—an inverse effect to
multiply, and will most often produce a brighter result.
This blend mode—
screen. Base dark colors become darker and base light colors become lighter. Mid-range colors, such as a 50% gray, are unaffected.
darken blend mode compares the source image and backdrop image's dark color luminosity and selects the darkest of the two. It does this by comparing rgb values instead of luminosity (like
screen would do), for each color channel. With
lighten, new color values are often created from this comparison process.
lighten does the exact opposite of
Color dodge #
If you use
color-dodge, it lightens the background color to reflect the source color. Pure black colors see no effect from this mode.
Color burn #
color-burn blend mode is very similar to the
multiply blend mode, but increases contrast, resulting in more saturated mid-tones and reduced highlights.
Hard light #
hard-light creates a vivid contrast. This blend mode either screens or multiplies luminosity values. If the pixel value is lighter than 50% gray, the image is lightened, as if it were screened. If it is darker, it's multiplied.
Soft light #
soft-light blend mode is a less-harsh version of
overlay. It works in very much the same way with less contrast.
A good way to picture how
difference works is a bit like how a photo negative works. The
difference blend mode takes the difference value of each pixel, inverting light colors. If the color values are identical, they become black. Differences in the values will invert.
exclusion is very similar to
difference, but instead of returning black for identical pixels, it will return 50% gray, resulting in a softer output with less contrast.
Non-separable blend modes #
You can think of these blend modes like HSL color components. Each takes a specific component value from the active layer and mixes it with other component values.
hue blend mode takes the hue of the source color and applies it to the saturation and luminosity of the backdrop color.
This works like
hue, but using
saturation as the blend mode applies the saturation of the source color to the hue and luminosity of the backdrop color.
color blend mode will create a color from the hue and saturation of the source color and the luminosity of the backdrop color.
luminosity is the inverse of
color. It creates a color with the luminosity of the source color and the hue and saturation of the backdrop color.
isolation property #
If you set the
isolation property to have a value of
isolate, it will create a new stacking context, which will prevent it from blending with a backdrop layer. As you learned in the z-index module, when you create a new stacking context, that layer becomes the base layer. This means that parent-level blend modes will no longer apply, but elements inside of an element with
isolation: isolate set can still blend.
Note that this doesn't work with
background-blend-mode because the background property is already isolated.
Which of following are CSS blend modes?Difference Lighten Brighten Dullen Multiply Overlay
If you want to blend different colors in different ways, which style of blend mode would you need?Separable Non-separable
These blend modes feature color channel targeted effects
Try again, non-separable are not color channel aware