Languages
[Edit]
EN

CSS - flip image horizontally

0 points
Created by:
Palpys
764

In this article, we would like to show you how to flip image horizontally using CSS.

Quick solution:

.flipped {
    transform: scaleX(-1);
}

or:

.flipped {
    transform: rotateY(180deg);
}

 

Practical examples

1. Using scaleX(-1)

In this example, we use transform css property with scaleX() function set to -1  to flip image horizontally and get the mirror image.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .flipped {
        transform: scaleX(-1);
    }

  </style>
</head>
<body>
  <div>Original image:</div>
  <img src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  <br>
  <div>transformed image</div>
  <img class="flipped" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
</body>
</html>

2. Using rotateY(180deg)

In this solution, we rotate the image by an angle of 180 degrees using rotateY() function.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .flipped {
        transform: rotateY(180deg);
    }

  </style>
</head>
<body>
  <div>Original image:</div>
  <img src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
  <br>
  <div>transformed image</div>
  <img class="flipped" src="https://dirask.com/static/bucket/1631898942509-VMYrnXyYZv--image.png" />
</body>
</html>

See also

  1. CSS - flip image vertically

  2. CSS - flip image both vertically and horizontally

References

  1. transform - CSS: Cascading Style Sheets | MDN
  2. scaleX() - CSS: Cascading Style Sheets | MDN
  3. rotateY() - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. CSS - rotate image 180 degrees y-axis
  2. CSS - get horizontal mirror image (y-axis reflection)
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join