The Wayback Machine - https://web.archive.org/web/20240131203132/https://www.geeksforgeeks.org/how-to-change-image-on-hover-with-css/
Open In App
Related Articles

How to change image on hover with CSS ?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The approach of this article is to change an image when the user hovering the mouse over it. This task can be simply done by using the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover. 

Example:

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>
        How to Change Image on 
        Hover in CSS
    </title>
      
    <style>
        .sudo {
            width: 230px;
            height: 195px;
            margin: 50px;
            background-image: url(
        }
  
        .sudo:hover {
            background-image: url(
        }
    </style>
</head>
  
<body>
    <h2>GeeksForGeeks</h2>
  
    <h2>
        How to change image on 
        hover with CSS
    </h2>
  
    <div class="sudo"></div>
</body>
  
</html>


Output:

Before hovering the mouse over the image:

After hovering the mouse over the image: 

Supported Browsers are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 26 Nov, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials