How to flip an image with CSS
Updated · Web
Add transform: scaleX(-1); to the image to mirror it horizontally, or transform: scaleY(-1); to flip it vertically. The file itself is not changed; only how the browser draws it.
Quick answer
- Horizontal mirror: img { transform: scaleX(-1); }
- Vertical flip: img { transform: scaleY(-1); }
- Both at once: transform: scale(-1, -1);
On this page
The basic rule
.mirror {
transform: scaleX(-1);
}scaleX(-1) scales the element by −1 along the horizontal axis, which mirrors it around its centre. It works on <img>, <video>, <canvas>, inline SVG and any other element. Every current browser supports it without prefixes.
| Declaration | Result |
|---|---|
scaleX(-1) | Mirror left–right |
scaleY(-1) | Flip top–bottom |
scale(-1, -1) | Both; looks like a 180° rotation |
rotateY(180deg) | Mirror left–right via a 3D turn; useful for card-flip animations |
rotate(180deg) | Upside down, not mirrored |
The live demo below applies these to an image so you can compare them.
Combining with other transforms
transform takes a list, and a new transform declaration replaces the old one rather than adding to it. If the image is already rotated or scaled, include everything in one declaration:
.photo {
transform: rotate(5deg) scaleX(-1);
}Order matters: transforms apply from right to left. Alternatively, use the individual scale property, which combines with transform: scale: -1 1;.
Transform origin and layout
The flip happens around the element's centre by default (transform-origin: 50% 50%), so the image stays in place. Transforms never affect layout: the element keeps its original box, and neighbouring elements do not move.
If you change transform-origin to an edge, the image swings across that edge and may overlap other content or be clipped by overflow: hidden on a parent.
Flipping a background image
There is no background-transform. Flipping the element itself would also mirror any text inside it. Put the background on a pseudo-element and flip only that:
.hero {
position: relative;
}
.hero::before {
content: "";
position: absolute;
inset: 0;
background: url(photo.jpg) center / cover;
transform: scaleX(-1);
z-index: -1;
}Right-to-left layouts
Directional icons such as arrows should point the other way on Arabic or Hebrew pages. Flip them only in RTL context:
[dir="rtl"] .icon-arrow {
transform: scaleX(-1);
}Do not mirror photos, logos or icons that have no direction (such as a search magnifier or a checkmark).
Animating a flip
Add a transition to animate between the normal and flipped state:
.card {
transition: transform 300ms ease;
}
.card.is-flipped {
transform: rotateY(180deg);
}
@media (prefers-reduced-motion: reduce) {
.card { transition: none; }
}rotateY gives a 3D turn when a parent has perspective set; scaleX animates as a squeeze through zero width.
When to flip the file instead
CSS only changes the display. If someone downloads the image, uses it in an email, or prints it from another program, they get the original. In those cases flip the file itself, for example with the mirror tool, and use the flipped file in your page.
Live CSS transform
This is a real CSS transform on an image in this page — not a screenshot. Toggle the buttons and watch the letters reverse.
img { transform: scaleX(-1); }Questions
Does scaleX(-1) change the image file?
No. It only changes how the browser displays the image. Saving the image gives the original file.
Can I flip an image with Tailwind CSS?
Yes. Tailwind's -scale-x-100 class sets a horizontal scale of -1, and -scale-y-100 flips vertically.
Does a flipped image affect accessibility?
Not by itself. Keep the alt text describing what the image shows; mention the mirroring only if it matters to the content.
Sources
Related guides
All guidesBasics
How to flip an image horizontally
Mirror a picture left to right, and the jobs where a horizontal flip is the right choice.
Basics
How to flip an image vertically
Mirror a picture top to bottom, and how a vertical flip differs from rotating it 180°.
Basics
Flip an image online
Flip a photo in the browser, what happens to your file, and which formats and sizes work.