Tsallaka zuwa abun ciki
Justice Tech School

Opacity versus Transparent Colours

opacity makes the whole element and its children transparent. rgba and hsla add alpha only to the colour, so text stays solid.

Example
<style>
.o { opacity: .4; background: #14b8a6; padding: 8px } .r { background: rgb(20 184 166 / .4); padding: 8px; margin-top: 6px }
</style>
<div class="o">opacity fades text too</div><div class="r">rgba fades only the background</div>

Exercise

Fade only the colour.

background: (0 0 0 / .5)

Quiz Test

What does opacity affect?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.