CSS Opacity

The opacity property in CSS allows you to set the transparency level of an element. It defines how transparent or opaque an element is, with values ranging from 0 (fully transparent) to 1 (fully opaque).

Key Points on CSS Opacity:

Syntax for CSS Opacity:

Syntax Example

/* Opacity syntax */
        opacity: value;
        
        /* Example */
        opacity: 0.5;

Examples of CSS Opacity:

The following examples demonstrate the usage of the opacity property:

Code Example: 50% Opacity


            div {
            opacity: 0.5;
                }

Output

This div has 50% opacity.

Code Example: 100% Opacity (Fully Opaque)


            div {
            opacity: 1;
                }

Output

This div has 100% opacity (fully opaque).

Common Opacity Use Cases:

To avoid unexpected results, be aware that the opacity affects the entire element. If you want to make only the background or text transparent, consider using rgba or hsla color values instead.