Open In App

How to flip an image on hover using CSS ?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, you will learn how to flip an image (add mirror effect), both horizontally and vertically when the mouse has hovered over it. This can be done by applying the transformation to the image as shown in the following example:

Example 1: This example represents how to flip image horizontally by transforming it along the X-axis using transform: scaleX(-1) property.




<!DOCTYPE html>
<html>
  
<head>
    <style>
        img:hover{
            transform: scaleX(-1);
        }
    </style>
</head>
  
<body>
    <h2>GeeksforGeeks</h2>
    <img src="gfg.jpg" width="50%">
</body>
  
</html>


Output:

Example 2: This example represents how to flip image vertically by transforming it along the Y-axis using transform: scaleY(-1) property.




<!DOCTYPE html>
<html>
  
<head>
    <style>
        img:hover{
            transform: scaleY(-1);
        }
    </style>
</head>
  
<body>
    <h2>GeeksforGeeks</h2>
    <img src="gfg.jpg" width="50%">
</body>
  
</html>


Output:



Last Updated : 29 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads