Change Image Opacity on Mouse Over

In this tutorial, we will learn how to change image opacity on the mouse over using CSS? By Apurva Mathur Last updated : July 24, 2023

Let's begin this topic by learning a bit about opacity property.

So, what is the purpose of opacity property?

The opacity property helps us to make text/images go transparent according to our preference. This can make your webpage look ravishing when used perfectly. We often use RGBA color codes in this to define the color of transparency and we apply opacity by giving one extra parameter into this RGBA code whose value will be from 0.0 to 1.0. These values fundamentally define the level of transparency we want. This value shows an effect in the form of increasing to decreasing (i.e.) 0.0 will be the most transparent one in comparison to 1.0. We can use this property with RGBA color code or we can also use this directly by specifying opacity.

To change the opacity on mouse hover we'll directly use selector: hover and we'll provide the opacity value.




<!DOCTYPE html>

         opacity: 0.2 ;
         opacity: 0.5;
      <img class="img1" src="" >
      <img class="img2" src=" >


Example: Change Image Opacity on Mouse Over


Here, I've taken two image tags and I've provided a unique class to these tags as this will be used as a selector for styling these image tags. After that just specify the links of the image enclosed with the URL keyword. Talking about the CSS part, give the appropriate height and width to the image and use the hover selector and specify the opacity.

CSS Examples »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.