CSS Reference ยท Filters, Masks and Shapes
The image-orientation property
Reference for the CSS image-orientation property: control whether browsers rotate photos using the EXIF orientation stored in the file, with a live example.
Cameras and phones often store a photo sideways and add an EXIF orientation tag that says "rotate this 90 degrees to display it upright". The image-orientation property controls whether the browser honors that tag when it draws the image.
Today the default is from-image: browsers apply the tag, so photos usually appear upright without any work from you. The property is mainly useful for the opposite case, none, which shows the raw pixels exactly as stored.
img.raw { image-orientation: none; }
Try it
Pick a photo taken on a phone held upright or sideways (any JPEG with an orientation tag). The image appears twice, once per value. For a file without an orientation tag, both look the same.
Syntax
image-orientation: from-image | none;
| Initial value | from-image |
| Applies to | All elements (affects the images they draw) |
| Inherited | Yes |
| Animatable | No |
| Computed value | As specified |
Values
| Value | Description |
|---|---|
from-image |
Rotates (and flips) the image according to the orientation metadata in the file. This is the default. |
none |
Ignores the metadata and draws the image as the stored pixel grid. |
Usage notes
- You rarely need it. Since the default honors EXIF, the property is useful mostly for reproducing a camera's raw output or for tools that edit the pixels themselves.
- Layout size follows the result. A photo stored landscape but flagged "rotate 90" is laid out as portrait with
from-image, and as landscape withnone. Dimensions you read in script fromnaturalWidthandnaturalHeightfollow the same rule in current browsers. - Old uploads. If you process uploaded photos on a server, strip or apply the tag there so every client shows the same orientation.
- Not a rotation tool. To rotate an image for design reasons, use
transformwithrotate(). - Older syntax. Earlier drafts allowed an angle and
flipkeywords; browsers did not implement them, so use only the two keywords above.
Browser support
Current browsers apply EXIF orientation by default, and the property is supported in modern versions of the major browsers. Check a compatibility table if you must support older ones, where the default orientation handling can differ between <img> and background images.