Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

Why does opacity make a whole element translucent instead of just its background?

Quick answer

The opacity property affects the element as a whole, including its contents, so text and other child content appear translucent along with the background. [S1] To make just the background translucent, put an alpha value in the background color instead; that leaves the text at its normal opacity. [S1] Choose the approach based on which parts you want to see through.

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I set opacity: 0.5 on a card to make its background see-through. Why did the text fade too?

Geez

opacity applies to the element as a whole, including its rendered contents, rather than just its background. [S1] So when you lower the card’s opacity, its text and other contents appear translucent too. If you want a translucent background but readable, normally opaque text, use an alpha channel in the background color instead. [S1]

For example, assuming the card contains a heading and paragraph, compare these two styles:

<div class="card faded-as-a-whole">
  <h2>Delivery details</h2>
  <p>Choose a delivery window.</p>
</div>

<div class="card translucent-background">
  <h2>Delivery details</h2>
  <p>Choose a delivery window.</p>
</div>
.faded-as-a-whole {
  background: navy;
  opacity: 0.5;
}

.translucent-background {
  background: rgb(0 0 128 / 50%);
}

In the first card, both the navy background and its contents look faded. In the second, the background color is translucent while the heading and paragraph retain their normal opacity. The exact appearance depends on what is behind the card.

Follow-up question

What does the alpha part of rgb(0 0 128 / 50%) mean here?

Geez

The / 50% is the color’s alpha value: it makes that background color translucent. [S1] Think of the background color as the part you want to soften, and leave the element’s opacity property alone when its text should stay undimmed.

Here is a practical swap. If your existing rule is:

.card {
  background: navy;
  opacity: 0.5;
}

change it to:

.card {
  background: rgb(0 0 128 / 50%);
}

The second rule applies transparency to the background color, not to the card and its contents as a group. [S1] The percentage is a starting point, not a guarantee that text will be easy to read in every design: check the result against the actual page behind the card.

Follow-up question

Could I keep both properties if I want the background extra faint?

Geez

You can use both, but they affect different things: the alpha value makes the background color translucent, and opacity affects the element and its contents together. [S1] So adding a lower opacity to a card with an alpha background will also make its text look translucent. If the goal is a faint background with solid-looking text, use the background alpha alone and adjust that value instead.

For instance, start with:

.card {
  background: rgb(0 0 128 / 25%);
}

If that still looks too strong over your page, try a lower background alpha. Check it in the context where the card appears, since the colors behind it affect what you see. This example explains the visual distinction; it does not establish how readable a particular color combination will be.

Follow-up question

What should I check if my text still looks faded after I change the background?

Geez

First, check whether the element or one of its containing elements still has an opacity value below 1; that property affects the rendered contents of the element it is applied to. [S1] Then check the background rule itself: it should use a color with an alpha value if only the background should be translucent. If the text still seems hard to distinguish, inspect the actual page background behind the card and adjust the design as needed.

A reusable before-and-after check:

  1. Find the rule setting opacity and remove it if you want the text to stay undimmed.
  2. Set the translucent color on background using an alpha channel.
  3. Look at the card over its real surrounding content and confirm the text looks as intended.

One limit to keep in mind: the cited guidance explains what opacity affects and how to make a background translucent; it does not determine whether a specific design is readable or provide a universal ideal alpha value. [S1]

A practical checklist

  • Decide whether you want the whole element faded or only its background translucent.

  • For a translucent background, use a color with an alpha value in the background declaration.

  • Remove a reduced opacity value if the element’s text should not fade with it.

  • Check the result over the actual background behind the element.

  • Review whether the text remains easy to distinguish in your design.

A few more useful answers

Does `opacity` apply only to child elements?

No. It affects the element as a whole, including its rendered contents; it is not an inherited property, but the contents are affected together. [S1]

What should I change if I want only the background to show through?

Use a background color with an alpha channel, such as background: rgb(0 0 0 / 40%), rather than lowering the element’s opacity. [S1]

Does setting opacity to zero remove an element?

No. Zero opacity does not remove the element from the DOM and does not necessarily prevent pointer interaction or keyboard focus. [S1]

Sources

References used for this guide.

  1. [S1] opacity CSS property — MDN
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work