Sub topic 12
Export dimensions and 1x/2x scales
This chapter assumes you know what a pixel is, that screens differ in density, and how to use frames and export settings in a design tool such as Figma or Sketch. It covers how to choose the pixel size of an exported file and how to produce the 2x version that sharp screens need.
Match the file to the displayed size
A design frame is measured in CSS pixels. A CSS pixel is the unit a web page uses for layout. On a standard screen, one CSS pixel is one device pixel. On a high-density screen, one CSS pixel covers a 2×2 block of device pixels, so a 2x screen needs twice as many image pixels in each direction to look sharp.
If a logo is displayed at 120 × 40 CSS pixels:
| Scale | Export size | Used for |
|---|---|---|
| 1x | 120 × 40 | Standard-density screens |
| 2x | 240 × 80 | Most phones, tablets, and modern laptops |
| 3x | 360 × 120 | A few high-end phones (rarely worth the bytes) |
Exporting at the displayed size gives you the smallest file that still looks right. Two mistakes are common:
- Too small. A 120-pixel file shown at 240 pixels is stretched, and it looks soft.
- Too large. A 4000-pixel photo shown at 400 pixels wastes bandwidth. The browser shrinks it, and the user pays for pixels that are never seen.
Export 1x and 2x from your design tool
Most design tools let you add several export rows to one layer. Set the scale on each row and add a suffix, so the files get distinct names.
- Select the layer or frame sized to its displayed dimensions (for example 120 × 40).
- Add an export row at
1xwith the suffix `(empty), which giveslogo.png`. - Add a second row at
2xwith the suffix@2x, which gives[email protected]. - Choose the format and export.
For wide images, work from the layout width. A hero image that fills a 800-pixel column is exported at 800 pixels wide for 1x and 1600 pixels wide for 2x. Height follows from the aspect ratio, so keep the proportions locked.
Tell the browser what you made
Two files help only if the page uses them. The srcset attribute lists the files, and the 1x and 2x labels say which density each one is for. The width and height attributes give the displayed size in CSS pixels, so the page reserves the right space before the image loads.
<img
src="logo.png"
srcset="logo.png 1x, [email protected] 2x"
width="120"
height="40"
alt="Acme logo">The browser picks logo.png on a standard screen and [email protected] on a high-density one. Note that width="120" stays the same for both files. It describes the display size, not the file size.
Common errors
- Exporting 2x and naming it as 1x, so the page shows an oversized file at the wrong scale.
- Leaving out
widthandheight, which makes the layout jump when the image loads. - Exporting vector files (SVG) at 1x and 2x. SVG scales without new files, so you only need one.
Exercise
A card image is displayed at 360 × 200 CSS pixels. What pixel sizes do you export for 1x and 2x, and which values go in the width and height attributes?
Show answer
Export 360 × 200 for 1x and 720 × 400 for 2x. The width and height attributes are 360 and 200, because they describe the displayed size in CSS pixels, not the size of either file.