Utilizor
Contact Us

CSS Opacity

The opacity property specifies the opacity/transparency of an element.

CSS Opacity / Transparency

The opacity property specifies the opacity/transparency of an element.

Example 1: Image Opacity

The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent.

Forest Forest

Example 2: Transparent Hover Effect

The opacity property is often used together with the :hover selector to change the opacity on mouse-over.

Forest

Example 3: Transparent Box

When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read.

This text is also transparent.

Example 4: Transparency using RGBA

If you do not want to apply opacity to child elements, use RGBA color values instead. The alpha channel (the 4th value) specifies the opacity for the color.

100% opacity
30% opacity (text is not affected)

Example

img {
  opacity: 0.5;
}

img:hover {
  opacity: 1.0;
}

div {
  background: rgba(76, 175, 80, 0.3);
}