--- title: opacity slug: Web/CSS/opacity tags: - CSS - CSS Reference - CSS3 - css3-color translation_of: Web/CSS/opacity ---
La propiedad CSS opacity define la transparencia de un elemento, esto es, en qué grado se superpone el fondo al elemento.
Usar esta propiedad con un valor diferente a 1 situa al elemento en un nuevo contexto de apilamiento.
{{cssinfo}}
opacity: <valor alfanumérico>
<alphavalue>| valor | Significado |
|---|---|
0 |
El elemento es transparente (invisible). |
| Cualquier valor entre 0 y 1 | El elemento es translúcido. |
1 |
El elemento es opaco (sólido). |
hbox.example {
opacity: 0.5; /* see the background through the hbox */
}
pre { /* make the box translucent (20% opaque) */
border: solid red;
opacity: 0.2;
filter: alpha(opacity=20); /* IE8 and lower */
zoom: 1; /* set "zoom", "width" or "height" to trigger "hasLayout" in IE 7 and lower */
}
pre { /* make the box translucent (50% opaque) */
border: solid red;
opacity: 0.5;
filter: alpha(opacity=50); /* IE8 and lower */
zoom: 1; /* set "zoom", "width" or "height" to trigger "hasLayout" in IE 7 and lower */
}
pre { /* make the box translucent (80% opaque) */
border: solid red;
opacity: 0.8;
filter: alpha(opacity=80); /* IE8 and lower */
zoom: 1; /* set "zoom", "width" or "height" to trigger "hasLayout" in IE 7 and lower */
}
<!doctype html>
<html>
<head>
<style>
img.opacity {
opacity: 1;
filter: alpha(opacity=50);
zoom: 1;
}
img.opacity:hover {
opacity: 0.5;
filter: alpha(opacity=100);
zoom: 1;
}
</style>
</head>
<body>
<img src="//developer.mozilla.org/media/img/mdn-logo.png" alt="MDN logo" width="128" height="146" class="opacity">
</body>
</html>
| Especificación | Estado | Comentarios |
|---|---|---|
| {{ SpecName('CSS3 Transitions', '#animatable-css', 'opacity') }} | {{ Spec2('CSS3 Transitions') }} | Define opacity como una animación. |
| {{ SpecName('CSS3 Colors', '#opacity', 'opacity') }} | {{ Spec2('CSS3 Colors') }} | Definición inicial |