CSS Opacity Tutorial

G:hackHTMLmyCSS-Tutorial16-opacity�1.jpg

Opacity

There’s a property called “opacity” and we use this property in order to change the transparency of an element. This property can be a text based element like <p>, <h1-h6> or it can be elements like<img>, <table>, <div> etc.

The value we set for this property, ranged from 0 to 1 where 1 means without any transparency and 0 means fully transparent.

Example:

<!DOCTYPE html>
<html>
<head>
   <title>CSS is fun :)</title>

   

  <style type="text/css">
      img{
         width: 200px;
         height: 200px;
         opacity: 0.5;
      }
      img:hover{
         opacity: 1;
      }

      

  </style> 
</head>
   <body>
      <figure>
         <figcaption>Hover over the picture below to see it without transparency</figcaption>
         <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/599px-The_Earth_seen_from_Apollo_17.jpg" alt=" earth viewed from space">

         

      </figure>

      

   </body>
</html>