Sub topic 11
Export 1x, 2x, and 3x versions for high-density screens
This chapter assumes you can resize an image with Image Size, know that a CSS pixel is not always one device pixel, and have used Export As or Quick Export at least once. It covers how to plan scaled exports, produce them in Photoshop, and serve them in HTML.
Why one file is not enough
A high-density (Retina) screen packs more physical pixels into each CSS pixel. A phone with a device pixel ratio (DPR) of 2 draws every CSS pixel using a 2×2 block of device pixels. If your page shows an image 400 CSS pixels wide, a 400 px file gets stretched to 800 device pixels. The browser has to invent the missing detail, so the image looks soft.
The fix is to supply more pixels than the layout needs. For a slot that is 400 CSS pixels wide:
| Scale | DPR it serves | File width | Typical use |
|---|---|---|---|
| 1x | 1 | 400 px | Older desktop monitors |
| 2x | 2 | 800 px | Most laptops and phones |
| 3x | 3 | 1200 px | Some high-end phones |
File size grows with the square of the scale, because you double both width and height. A 2x file has about four times the pixels of a 1x file. Compressed size rarely scales exactly that way, but expect it to grow a lot.
Plan from the largest size
Always design and export downward. Scaling up never recovers detail, so decide the largest scale you will ship and make sure the source can supply it.
- Work out the CSS size of the slot, for example 400 × 267.
- Multiply by the largest scale. For 3x, that is 1200 × 801.
- Check that your source has at least those pixels. If it does not, ship a lower maximum scale instead of upscaling.
Smart objects help here. If you place artwork as a smart object, Photoshop keeps the original pixels, so resizing the object down and back up does not degrade it. Raw pixel layers lose data every time you shrink them.
Export scales with Export As
Export As has a scale control that does the arithmetic for you.
- Choose File > Export > Export As.
- In the right panel, under Image Size, open the Scale menu. It offers presets such as 0.5x, 1x, 2x, and 3x, and a custom value.
- Pick a scale and check that the Width and Height fields show the pixel result you expect.
- Set the format and quality, then click Export.
Here the scale is applied to the current canvas size. So the canvas must already match your 1x size, or your math is off. If your document is built at 2x, which is common, export it at 1x for the full file and at 0.5x for the half-size file.
The Resample menu in this panel decides how the pixels are recalculated. Bicubic Smoother suits enlarging. Bicubic Sharper suits reducing and keeps edges crisper. For icons and pixel art, Nearest Neighbor avoids blurry edges.
Export several scales in one pass
Export As exports one scale at a time, unless you add more entries in the Scale list. Both Quick Export and Export As can use the multi-scale feature in different ways, so the most dependable method for production is Generate Image Assets.
Generate Image Assets
Turn it on with File > Generate > Image Assets. Photoshop then watches the document. Whenever you save or edit, it re-exports every layer or group whose name follows the naming rules. The files land in a folder named after the document, with an -assets suffix, next to the PSD.
Name a layer or group like this:
hero.jpg90%
icon-search.png
icon-search-2x.png
200% badge.png
300x300 avatar.jpgThe rules in these names:
- The file extension sets the format. Supported extensions include
.jpg,.png,.gif, and.svg. - A percentage right after the extension sets JPEG quality.
hero.jpg90%exports at quality 90. - A prefix such as
200%scales the layer to that percentage of its current size.200% badge.pngmakes a file twice as big as the layer. - A prefix such as
300x300forces exact pixel dimensions. - A comma lets one layer produce several files, for example
100% icon.png, 200% [email protected].
Be careful with the percentage prefix. It scales up from the layer's size. If your layer is the 1x artwork, 200% upscales it and gives you no new detail. To get a real 2x file, build the layer at your largest size, then use a percentage under 100% for the smaller ones:
100% [email protected], 50% icon.pngName files so code can find them
Two conventions are common, and which one you use depends on how you deliver the images.
- Suffix naming:
icon.png,[email protected],[email protected]. Used by native app asset catalogs and many CSS workflows. - Width naming:
photo-800.jpg,photo-1600.jpg. Used withsrcsetwidth descriptors, where the name records the real pixel width.
Pick one per project and keep it consistent so build scripts and teammates can predict file names.
Serve the right file in HTML
Exporting is only half the job. The browser picks a file based on the markup you give it. There are two ways to describe your files.
Density descriptors
Use x descriptors when the displayed size is fixed, as with an icon or logo:
<img
src="logo.png"
srcset="logo.png 1x, [email protected] 2x, [email protected] 3x"
width="200" height="60"
alt="Company logo">The width and height attributes give the CSS size, so the layout does not jump while the image loads.
Width descriptors
Use w descriptors for fluid photos. You list each file's real pixel width, and sizes tells the browser how wide the slot will be:
<img
src="photo-800.jpg"
srcset="photo-800.jpg 800w, photo-1600.jpg 1600w"
sizes="(max-width: 800px) 100vw, 800px"
width="800" height="533"
alt="Describe the photo">The browser multiplies the slot width from sizes by its DPR, then picks the smallest file that is large enough. On a 400 px wide phone with DPR 2, the slot needs 800 pixels, so it takes photo-800.jpg. On a 1000 px desktop window at DPR 2 it needs 1600, so it takes photo-1600.jpg.
Edge cases and common errors
- Upscaled "2x" files. If the 2x image came from enlarging a 1x file, it is no sharper and is larger. Compare the two at 100% zoom before shipping.
- Odd dimensions. A 1x size of 301 px gives 602 at 2x, which is fine, but a 0.5x export of an odd 2x size produces a fractional dimension that Photoshop rounds. Design at even pixel sizes to keep 1x and 2x aligned.
- Wrong source density. Photoshop's resolution field (72, 144 ppi) does not make a file Retina. Only the pixel dimensions matter for web delivery.
- Format mix-ups. Export photos as JPEG or WebP at each scale. Export flat icons as PNG or SVG. An SVG needs no scaled copies at all, since it is vector.
- Missing
widthandheight. Without them the page shifts as images load, which hurts layout stability. - Too many variants. Each extra file is another asset to produce and test. Two or three widths usually cover real devices.
A small workflow
- Build the document at your largest target size, with artwork as smart objects.
- Name layers with comma-separated rules to get each scale.
- Run Generate Image Assets and open the output folder.
- Check each file's pixel width, size on disk, and look at 100% zoom.
- Add the files to your
srcsetand test in a browser using the device toolbar at DPR 1, 2, and 3.
Exercise
A hero image fills a 600 CSS pixel wide slot. You want files for 1x and 2x. What pixel widths do you export, and what should your layer name look like in Generate Image Assets if the layer is built at the 2x size? Why not build it at 1x and use 200%?
Show answer
Export 600 px for 1x and 1200 px for 2x. With the layer built at 1200 px, name it something like 100% [email protected], 50% hero.jpg. Building at 1x and using 200% would only enlarge the pixels, so the 2x file would be bigger on disk and no sharper than the 1x one.
Exercise
A page shows a photo in a slot that is 500 CSS pixels wide. You list photo-800.jpg 800w and photo-1600.jpg 1600w, and sizes="500px". Which file does a device with DPR 2 download, and which does a DPR 1 device download?
Show answer
The DPR 2 device needs 500 × 2 = 1000 pixels, so it downloads photo-1600.jpg, the smallest file that is at least 1000 px wide. The DPR 1 device needs 500 pixels, so it downloads photo-800.jpg.