Blend Modes Stay organized with collections Save and categorize content based on your preferences.
The CSS Podcast - 024: Blend Modes
Duotone is a popular color treatment for photographywhich 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?
Using blend modes—and other techniques you have learned about,such asfilters andpseudo-elements—you can apply this effect to any image.
What is a blend mode?
Blend modes are commonly used in design tools such as Photoshopto 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 themix-blend-mode or thebackground-blend-mode properties.Themix-blend-mode applies blending to a whole elementand thebackground-blend-mode applies blending to the background of an element.
You usebackground-blend-mode when you have multiple backgrounds on an elementand want them all to blend into each other.
Themix-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
mix-blend-mode
background-blend-mode
Separable blend modes
Normal
This is the default blend mode and changes nothing about how an element blends with others.
Multiply
Themultiply 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.
.my-element{mix-blend-mode:multiply;}Screen
Usingscreen multiplies thelight values—an inverse effect tomultiply,and will most often produce a brighter result.
.my-element{mix-blend-mode:screen;}Overlay
This blend mode—overlay—combinesmultiply andscreen.Base dark colors become darker and base light colors become lighter.Mid-range colors, such as a 50% gray, are unaffected.
.my-element{mix-blend-mode:overlay;}Darken
Thedarken blend mode compares the source image and backdrop image's dark color luminosityand selects the darkest of the two.It does this by comparing rgb values instead of luminosity (likemultiply andscreen would do),for each color channel.Withdarken andlighten, new color values are often created from this comparison process.
.my-element{mix-blend-mode:darken;}Lighten
Usinglighten does the exact opposite ofdarken.
.my-element{mix-blend-mode:lighten;}Color dodge
If you usecolor-dodge, it lightens the background color to reflect the source color.Pure black colors see no effect from this mode.
.my-element{mix-blend-mode:color-dodge;}Color burn
Thecolor-burn blend mode is very similar to themultiply blend mode,but increases contrast, resulting in more saturated mid-tones and reduced highlights.
.my-element{mix-blend-mode:color-burn;}Hard light
Usinghard-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.
.my-element{mix-blend-mode:hard-light;}Soft light
Thesoft-light blend mode is a less-harsh version ofoverlay.It works in very much the same way with less contrast.
.my-element{mix-blend-mode:soft-light;}Difference
A good way to picture howdifference works is a bit like how a photo negative works.Thedifference 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.
.my-element{mix-blend-mode:difference;}Exclusion
Usingexclusion is very similar todifference,but instead of returning black for identical pixels,it will return 50% gray, resulting in a softer output with less contrast.
.my-element{mix-blend-mode:exclusion;}Non-separable blend modes
You can think of these blend modes like HSLcolor components.Each takes a specific component value from the active layer and mixes it with other component values.
Hue
Thehue blend mode takes the hue of the source colorand applies it to the saturation and luminosity of the backdrop color.
.my-element{mix-blend-mode:hue;}Saturation
This works likehue,but usingsaturation as the blend mode applies the saturation of the source colorto the hue and luminosity of the backdrop color.
.my-element{mix-blend-mode:saturation;}Color
Thecolor blend mode will create a color from the hue and saturation of the source colorand the luminosity of the backdrop color.
.my-element{mix-blend-mode:color;}Luminosity
Lastly,luminosity is the inverse ofcolor.It creates a color with the luminosity of the source color and the hue and saturation of the backdrop color.
.my-element{mix-blend-mode:luminosity;}Theisolation property
If you set theisolationproperty to have a value ofisolate,it will create a new stacking context,which will prevent it from blending with a backdrop layer.As you learned in thez-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 withisolation: isolate set canstill blend.
Note that this doesn't work withbackground-blend-modebecause the background property is already isolated.
Check your understanding
Test your knowledge of blend-modes
Which of following are CSS blend modes?
If you want to blend different colors in different ways, which style of blend mode would you need?
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-05-04 UTC.