Semi-transparent Background Colors
suggest changeThe 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents