Skip to main content
Syllabus
On this page

CSS Opacity & Blend Modes

Badar KhalilUpdated September 29, 2026 5 min read

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.

Code
.faded { opacity: 0.5; }

2. opacity vs Color Alpha (rgba, hsl / alpha)

opacityColor with alpha
AffectsThe entire element and all childrenOnly that one color (background, border, text...)
ChildrenCannot be made more opaque than the parentChildren stay fully opaque
Exampleopacity: .6background: 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 opacity value less than 1 creates a new stacking context. This can change how z-index works for the element's children.
  • An element with opacity: 0 is invisible but still takes space, still receives clicks and can still be focused by keyboard. Add visibility: hidden or pointer-events: none when hiding interactive content.
  • Screen readers still read content with opacity: 0. Use display: none or hidden to 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;.

ModeEffectTypical use
normalDefault, no blendingEveryday elements
multiplyDarkens; white becomes transparentShadows, logos on colored backgrounds, duotone
screenLightens; black becomes transparentGlows, light leaks
overlayBoosts contrast, mixes multiply and screenTextures, color grading
darken / lightenKeeps the darkest or lightest channelLayering shapes
color-dodge / color-burnStrong brighten or darken effectsHighlights, dramatic looks
differenceSubtracts colors; creates inverted looksText that stays visible on any background
hue, saturation, color, luminosityApplies a single HSL componentRecoloring 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: screen or multiply over an image.
  • Auto-contrast text: white text with mix-blend-mode: difference stays readable over both light and dark areas.
  • Duotone photo: grayscale image plus a colored layer with mix-blend-mode: multiply or lighten.
  • Logo on any color: a logo with white background using mix-blend-mode: multiply looks 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: isolate on 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 opacity on a container and making its text faded too.
  • Leaving an opacity: 0 button 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) with background-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.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Exercise: Semi-transparent Banner With Sharp TextHTML

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.

Try it Yourself HTML
Output

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.

Exercise: Duotone Effect With Blend ModesHTML

Create a duotone look on .photo by combining a background-color (#0ea5e9) with the existing gradient image layer using background-blend-mode: multiply.

Try it Yourself HTML
Output

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.

Quiz: Opacity & Blend Modes Quiz Pass 70%
Loading quiz…

Was this page helpful?