Skip to content
Related Articles

Related Articles

Improve Article
How to flip an image on hover using CSS ?
  • Last Updated : 29 Jun, 2020

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:




My Personal Notes arrow_drop_up
Recommended Articles
Page :