The CSS opacity property sets how transparent an element is, using a number from 0 (fully transparent) to 1 (fully opaque). opacity: 0.5 makes the element and everything inside it, including text, borders and child elements, half see-through. It applies to the element as a whole, not just its background.
That "whole element" behavior is the main thing to learn about css opacity. If you only want a see-through background, use a color with an alpha channel instead. This guide covers the values, how opacity affects children, how it compares with rgba(), and its side effects on stacking and events.
opacity accepts a number between 0 and 1, or a percentage in modern browsers:
| Value | Result |
|---|---|
1 | Fully opaque, the default |
0.5 or 50% | Half transparent |
0 | Fully transparent, still takes up space |
| Values outside 0 to 1 | Clamped to the nearest limit |
Opacity is not inherited, but it still affects every descendant because the browser renders the element and its children into a group first, then blends that group with what is behind it.
The blue box and its white text both become 40 percent opaque, so the yellow wrapper shows through both.
Because the whole subtree is composited as one layer, you cannot set a child to opacity: 1 to "undo" a parent's opacity: 0.5. The child can only be as opaque as its parent allows.
If you want a semi-transparent background but solid text, do not fade the parent. Put the transparency on the background color only, as the next section shows.
Modern CSS colors support an alpha channel. Using it affects only the property it is written on.
| Goal | Use |
|---|---|
| Fade an entire component, image or button | opacity |
| See-through background, solid text | rgb(... / alpha), hsl(... / alpha) or rgba() |
| See-through border only | A border color with alpha |
| Fade a background image only | A pseudo-element with opacity, or a gradient with alpha stops |
The space-separated syntax rgb(0 0 0 / 0.6) is the current standard, and the comma form rgba(0, 0, 0, 0.6) still works everywhere.
Setting opacity to anything below 1 has consequences beyond how things look.
z-index can no longer escape above siblings of the parent, which sometimes breaks dropdowns or tooltips.opacity: 0. An invisible button at zero opacity is still clickable and can still be focused with the keyboard.To remove an element from interaction as well, combine it with other properties:
Use display: none or the hidden attribute when the element should disappear entirely and be skipped by assistive tools.
opacity is one of the cheapest properties to animate because browsers can handle it on the GPU compositor without recalculating layout.
Other common uses are dimming disabled controls (opacity: 0.5), dimming inactive tabs, and building modal backdrops. Be careful with low-opacity text: faded text often fails the contrast ratio that accessibility guidelines require, so check contrast after fading.
The default is 1, meaning fully opaque. The property is not inherited.
No. The element stays in the layout and still receives pointer events and keyboard focus. Add pointer-events: none or visibility: hidden if it should not be interactive.
Use a color with an alpha channel, such as background: rgb(0 0 0 / 0.5), instead of opacity. Text and children then stay fully opaque.
No. visibility: hidden hides the element but keeps its space and removes it from interaction, while opacity: 0 keeps it interactive and visible to assistive tools.
opacity takes a value from 0 to 1 and fades the element together with all its content. Children cannot override it, so use alpha colors when only a background should be see-through. It creates a stacking context, does not remove the element from layout or interaction, and animates efficiently, which makes it ideal for fades and hover effects.