opacity

Jump to: navigation, search

opacity


W3C Recommendation

Summary

The opacity property controls transparency and opacity of an element. Its values range from 0 to 1. Assuming defaults at parent level, an element with an opacity of 1 is completely opaque, whereas and element with an opacity of 0 is completely transparent. The opacity used when rendering an element is the product of its opacity and the opacity of its ancestors.

Overview table

Initial value 1
Applies to All elements
Inherited No
Media visual
Computed value [[Computed value::The same as the specified value after clipping the <alphavalue> to the range [0.0,1.0]]]
Animatable Yes
CSS Object Model Property opacity

Syntax

  • opacity: alpha-value
  • opacity: inherit


Values

alpha-value
A floating-point value between 0.0 (fully transparent) and 1.0 (fully opaque), inclusive. Any values outside the range will be clamped to this range.
inherit
Indicates that the property takes the same computed value as the property for the element's parent.


Examples

View live example

CSS

.example1 {
  opacity: 0.5;
}

Usage

As an alternative to the visibility property, an element's opacity can be set to 0 to make the element take space but not appear.

It's important to note that opacity affects not only a given element, but all of the elements which it contains.

Notes

The opacity setting is applied uniformly across the entire object. Any values outside the range 0.0 to 1.0 will be clamped to this range.

Object or group opacity can be thought of conceptually as a postprocessing operation. Conceptually, after the object or group is rendered into an RGBA offscreen image, the object or group opacity setting specifies how to blend the offscreen image into the current background.

Note that setting a value smaller than 1 to this property creates a new stacking context. For more information, see What No One Told You About Z-Index by Philip Walton.


Related specifications

Specification Status Related Changes
CSS Color Module Level 3 Recommendation Section 1.2

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 1
1
9
9
1.2
1 -webkit

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic Support 2.1
7
18
15
9
10
5
3.1


Compatibility notes

Browser Version Note
Internet Explorer 5-7 You can use filter: alpha(opacity=50); to obtain the same effect
Internet Explorer 8 You can use -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; to obtain the same effect

See also

Related articles

Visual Effects















  • opacity

















Other articles

filter

Related pages (MSDN)

Attribution

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]