Summary
The opacity CSS property specifies the transparency of an element, that is, the degree to which the background behind the element is overlaid.
The value applies to the element as a whole, including its contents, even though the value is not inherited by child elements. Thus, an element and its contained children all have the same opacity relative to the element's background, even if the element and its children have different opacities relative to one another.
Using this property with a value different than 1 places the element in a new stacking context.
- Initial value
1.0 - Applies to all elements
- Inherited no
- Media
visual - Computed value the specified value, clipped in the range
[0,1] - Animatable yes, as a number
- Canonical order the unique non-ambiguous order defined by the formal grammar
Syntax
Formal syntax: <number>
opacity: 1 opacity: 1.0 opacity: 0.6 opacity: 0.0 opacity: 0 opacity: inherit
Values
-
<number> -
Is a
<number>in the range0.0to1.0, both included, representing the opacity of the channel, that is the value of its alpha channel. Any value outside the interval, though valid, is clamped to the nearest limit in the range.Value Meaning 0The element is fully transparent (that is, invisible). Any <number>strictly between0and1The element is translucent (that is, background can be seen). 1The element is fully opaque (solid).
Examples
Basic example
div { background-color: yellow; }
.light {
opacity: 0.2; /* Barely see the text over the background */
}
.medium {
opacity: 0.5; /* See the text more clearly over the background */
}
.heavy {
opacity: 0.9; /* See the text very clearly over the background */
}
<div class="light">You can barely see this.</div> <div class="medium">This is easier to see.</div> <div class="heavy">This is very easy to see.</div>
Different opacity with :hover
img.opacity {
opacity: 1;
filter: alpha(opacity=100); /* IE8 and lower */
zoom: 1; /* Triggers "hasLayout" in IE 7 and lower */
}
img.opacity:hover {
opacity: 0.5;
filter: alpha(opacity=50);
zoom: 1;
}
<img src="//developer.mozilla.org/media/img/mdn-logo.png"
alt="MDN logo" width="128" height="146"
class="opacity">
Specifications
| Specification | Status | Comment |
|---|---|---|
| CSS Transitions The definition of 'opacity' in that specification. |
Working Draft | Defines opacity as animatable. |
| CSS Color Module Level 3 The definition of 'opacity' in that specification. |
Recommendation | Initial definition |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1.7 or earlier) | 9.0 | 9.0 | 1.2 (125) |
8.0filter: alpha(opacity=xx)(both are synonymous) |
|||||
4.0filter: alpha(opacity=xx) |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | 1.0 | 1.0 (1.7) | 9.0 | 9.0 | 3.2 |
8.0filter: alpha(opacity=xx)(both are synonymous) |
|||||
4.0filter: alpha(opacity=xx) |
- History: Prior to Mozilla 1.7 (Firefox 0.9) the
-moz-opacityproperty was implemented in a non-standard (inherited) way. With Firefox 0.9 the behavior changed and the property was renamed toopacity. Since then-moz-opacitywas supported just as an alias foropacity. - Gecko 1.9.1 (Firefox 3.5) and later do not support
-moz-opacityand support forMozOpacityin javascript was removed in Gecko 13. By now, you should be using simplyopacity. - Prior to version 9, Internet Explorer does not support
opacity, rather it supportsfilterinstead. - IE4 to IE9 supported the extended form
progid:DXImageTransform.Microsoft.Alpha(Opacity=xx). - IE8 introduced
-ms-filter, which is synonymous withfilter. Both are gone in IE10 - Similar to
-moz-opacity,-khtml-opacityhas been dead since early 2004 (release of Safari 1.2).
Konqueror never had support for-khtml-opacityand had been supportingopacitysince version 4.0.
See also
Document Tags and Contributors
Contributors to this page: Fredchat, Spanglerco, Jürgen Jeka, sebmozilla, kscarfone, Dbs, mattbrundage, Huan, myakura, webposible, Sheppy, tregagnon, jswisher, andershaig, fscholz, Nickolay, Waldo, FredB, DBaron, grendel, McGurk, Oleg85, ethertank, hydrurga, teoli, BijuGC, Mgjbot, aakoch, Keepitmassive, j.j.
Last updated by:
Dbs,