Use the opacity property with the :hover selector to change the opacity on mouse-over. Following is the code to change image opacity on mouse over −
Example
<!DOCTYPE html>
<html>
<head>
<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.transparent{
width:270px;
height:200px;
opacity: 1;
transition: 0.3s;
}
.transparent:hover{
opacity: 0.3;
}
</style>
</head>
<body>
<h1>Image opacity on hover example</h1>
<img class="transparent" src="https://i.picsum.photos/id/505/800/800.jpg" >
<h2>Hover over the above image to change its opacity</h2>
</body>
</html>Output
The above code will produce the following output −
