Semi-transparent Background Colors

suggest change

The opacity property affects an entire element, including its descendants. To make only the background translucent, put an alpha component in the color:

.overlay {
  background-color: rgb(0 0 0 / 60%);
  color: white;
}

The modern space-separated rgb() syntax accepts an optional alpha value after /. The comma-separated rgba(0, 0, 0, 0.6) spelling remains valid but is no longer required.

For a reusable color, combine custom properties with relative composition:

:root {
  --overlay-color: 0 0 0;
}

.overlay {
  background-color: rgb(var(--overlay-color) / 60%);
}

Legacy Internet Explorer gradient filters are obsolete and should not be used as an opacity fallback.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents