Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Colors and Backgrounds

The opacity property

Reference for the CSS opacity property: how it fades an element and its children, the stacking context it creates, how it differs from rgba colors, and examples.

The opacity property controls how transparent an element is. A value of 1 is fully opaque, 0 is fully transparent, and values in between let whatever is behind the element show through.

Opacity applies to the element as a whole: its background, border, text and all of its descendants are first drawn together as a group, and the group is then faded. That is why a child can never be more opaque than its parent.

CSS
.disabled { opacity: 0.5; }
.ghost { opacity: 25%; }

Try it

Fading an element and its children
opacity versus a translucent background

Syntax

CSS
opacity: <alpha-value>;   /* <number> | <percentage> */

opacity: 0.75;
opacity: 75%;
  • Initial value: 1
  • Applies to: all elements
  • Inherited: no (but the fade does cover all descendants, because they are painted as part of the element's group)
  • Animatable: yes (as a number)
  • Computed value: the specified number, clamped to the range 0 to 1

Values

Value Description
1 (or 100%) Fully opaque. The default.
A number between 0 and 1 Partly transparent. 0.5 is half transparent.
0 (or 0%) Fully transparent. The element is invisible but still takes space and still receives clicks.
Out-of-range values Values below 0 are treated as 0 and above 1 as 1.

Usage notes

  • A child cannot undo its parent's opacity. Setting opacity: 1 on a child of a 0.5 parent does not bring it back. To fade only a background, use a color with alpha such as rgb(0 0 0 / 50%) or background-color with color-mix().
  • It creates a stacking context. Any value below 1 makes the element a stacking context, which can change how z-index works for its descendants and can trap position: fixed content inside its group.
  • opacity: 0 is not display: none. The element still occupies space, can be focused and clicked, and is still read by screen readers. Combine it with visibility: hidden or pointer-events: none if it should be truly inert.
  • Good for animation. Opacity is one of the cheapest properties to animate because browsers can often handle it on the compositor. Fade-ins and fade-outs are typical uses.
  • Disabled look. Fading a disabled control is common, but low opacity may fail contrast requirements; check the text remains readable.
  • Opacity is not a color. For text, prefer a translucent color; for SVG shapes there are also fill-opacity and stroke-opacity.

Browser support

Supported in every browser, including the percentage form in current ones.