How to flip an image on hover using CSS ?

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.