Background Image Opacity

The definitive guide to handling background transparency without affecting your text content.

The Wrong Way

opacity: 0.5

Unreadable Text

Everything gets faded

Setting opacity on the container fades everything, including your text and buttons.

The Right Way

::before

Crystal Clear

Only background is faded

Using a ::before pseudo-element lets you control image opacity independently of the content.

Generator

Tweak settings to generate your CSS.

0.5
#000000
.container {
  position: relative;
  background-color: #000000;
}

.container::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url(...);
  background-size: cover;
  opacity: 0.5;
}

Professional Design

Content remains perfectly legible while the background image fades into the color of your choice.