On this page
CSS Opacity & Blend Modes
What Are CSS Opacity and Blend Modes?
The CSS opacity property controls how transparent an element is, while blend modes control how an element's colors mix with whatever is behind it. Together they make overlays, fades, duotone images, text knockouts and Photoshop-like effects possible in pure CSS. Our focus keyword is CSS opacity, and you will also learn trending topics: opacity vs rgba, mix-blend-mode examples, background-blend-mode duotone, CSS isolation property, fade in and out transitions, and how opacity creates a stacking context.
1. The opacity Property
opacity accepts a number from 0 (fully transparent) to 1 (fully opaque), or a percentage such as 50%. It applies to the whole element, including its text, borders, background and all children.
.faded { opacity: 0.5; }2. opacity vs Color Alpha (rgba, hsl / alpha)
| opacity | Color with alpha | |
|---|---|---|
| Affects | The entire element and all children | Only that one color (background, border, text...) |
| Children | Cannot be made more opaque than the parent | Children stay fully opaque |
| Example | opacity: .6 | background: rgb(0 0 0 / 60%) |
To make a semi-transparent background with fully readable text, use color alpha, not opacity.
3. opacity Side Effects
- Any
opacityvalue less than 1 creates a new stacking context. This can change howz-indexworks for the element's children. - An element with
opacity: 0is invisible but still takes space, still receives clicks and can still be focused by keyboard. Addvisibility: hiddenorpointer-events: nonewhen hiding interactive content. - Screen readers still read content with
opacity: 0. Usedisplay: noneorhiddento remove it from the accessibility tree.
4. Fade Transitions
opacity is one of the best properties to animate because browsers can animate it on the GPU without triggering layout. Combine transition: opacity .3s with :hover for fades. For fade-outs that also remove the element, combine opacity with visibility or use the modern transition-behavior: allow-discrete together with @starting-style.
5. mix-blend-mode
mix-blend-mode blends an element with the content behind it (its parent's background and earlier siblings). The syntax is simply mix-blend-mode: multiply;.
| Mode | Effect | Typical use |
|---|---|---|
normal | Default, no blending | Everyday elements |
multiply | Darkens; white becomes transparent | Shadows, logos on colored backgrounds, duotone |
screen | Lightens; black becomes transparent | Glows, light leaks |
overlay | Boosts contrast, mixes multiply and screen | Textures, color grading |
darken / lighten | Keeps the darkest or lightest channel | Layering shapes |
color-dodge / color-burn | Strong brighten or darken effects | Highlights, dramatic looks |
difference | Subtracts colors; creates inverted looks | Text that stays visible on any background |
hue, saturation, color, luminosity | Applies a single HSL component | Recoloring images |
6. background-blend-mode
Blends the background layers of one element with each other and with its background color. It does not affect children or content. It is perfect for duotone images: set a background-color, add an image, and use background-blend-mode: multiply.
7. The isolation Property
Blend modes look at everything behind an element up to the nearest stacking context. Set isolation: isolate on a parent to create a new stacking context so its children blend only with each other, and not with the page behind. This avoids surprising results and unexpected color shifts.
8. Creative Techniques
- Text knockout: big text with
mix-blend-mode: screenormultiplyover an image. - Auto-contrast text: white text with
mix-blend-mode: differencestays readable over both light and dark areas. - Duotone photo: grayscale image plus a colored layer with
mix-blend-mode: multiplyorlighten. - Logo on any color: a logo with white background using
mix-blend-mode: multiplylooks transparent.
9. Performance and Accessibility
- Blend modes on large or many elements can be expensive because the browser must composite several layers. Test on mid-range phones.
- Blended colors change with the background, so verify text contrast in every case. Avoid blending for critical body text.
- Provide a fallback: unsupported browsers just show normal blending. All current browsers support the standard blend modes.
Best Practices
- Use color alpha for translucent backgrounds and opacity for fading whole components.
- Use
isolation: isolateon components that use blend modes. - Hide content properly (
hidden,display: none) when it should not be reachable. - Animate opacity and transform rather than layout properties.
Common Mistakes
- Using
opacityon a container and making its text faded too. - Leaving an
opacity: 0button clickable and focusable. - Forgetting that opacity below 1 creates a stacking context and breaks expected z-index layering.
- Confusing
mix-blend-mode(blends the element with what is behind) withbackground-blend-mode(blends only background layers).
Summary
Opacity fades whole elements, alpha colors fade individual paints, and blend modes mix layers like design software. Know the stacking-context effect, use isolation, and test contrast for effects that change with the background. Try the live examples below.
Press Run to execute.
Press Run to execute.
Press Run to execute.
Press Run to execute.
Press Run to execute.
The banner text becomes faded because opacity is used. Fix the CSS so the black background is 60% transparent but the white text stays fully sharp. Remove the opacity declaration.
Press Run to execute.
Show expected output
Translucent black banner with fully opaque white text.This is a self-check — compare your result with the expected output above.
Create a duotone look on .photo by combining a background-color (#0ea5e9) with the existing gradient image layer using background-blend-mode: multiply.
Press Run to execute.
Show expected output
The gradient is tinted with a blue color through multiply blending.This is a self-check — compare your result with the expected output above.
Was this page helpful?