CSS · CSS Tutorial · Lesson 31
CSS Opacity
Transparency of elements.
The opacity property specifies the transparency of an element, from 0.0 (fully transparent) to 1.0 (fully opaque).
Example
<style>
img { opacity: 0.5; transition: opacity .3s; }
img:hover { opacity: 1.0; }
.rgba { background: rgba(4, 170, 109, 0.3); padding: 10px; }
.op { background: rgb(4, 170, 109); opacity: 0.3; padding: 10px; }
</style>
<img src="https://picsum.photos/id/1015/200/120" alt="Lake"> (hover me)
<div class="rgba">RGBA background: text stays solid</div>
<div class="op">opacity: text becomes transparent too</div>
Tip: opacity affects the element and all of its children. To make only the background transparent, use an RGBA color.
Keep reading “CSS Opacity”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.