</> VirtualASP

Frontend lab

Ship images without making the page jump

An image needs a useful crop, an appropriate file and enough information for the browser to reserve its space.

A developer working with code across two screens

Begin with the space in the design

A photograph that appears as a narrow landscape banner needs a different crop from a portrait beside an interview. Decide what the reader needs to see before choosing an export size. CSS can crop an image, but it cannot recover a subject that was cut out of the source. Inspect both the wide and narrow layouts.

Reserve the image’s shape

Give the image accurate width and height attributes so the browser knows its aspect ratio before the download finishes. A fluid CSS width can still scale it to the available space. Avoid declaring a ratio that differs from the actual file unless the design deliberately uses a fixed crop and the CSS handles that crop.

Send a sensible file for the slot

An original camera image is rarely the right delivery file for a modest article column. Export a suitable size and compare the result at the size people will see it. Use responsive candidates where the layout warrants them. Inspect transferred bytes and visible detail together; a very small file that destroys a diagram is not an optimisation.

Load according to reading order

Images further down a long article can be lazy-loaded. The lead image that is visible immediately should normally be available without waiting for a scroll. Keep the markup understandable before adding a script-based loader. Test a slower connection to see whether the headline and introduction remain usable while media arrives.

Describe the purpose, not the file

For an informative image, write an alternative that conveys the relevant information. A purely decorative image can have an empty alternative. If the image is the only content of a link, its accessible text needs to explain the destination or action. A generic filename is not a useful substitute. Review the result with the image hidden as well as visible.

Put it into practice

<img src="workbench.webp"
     width="1200" height="800"
     alt="A developer comparing two page layouts">

img { max-width: 100%; height: auto; }

Illustrative markup. Use the dimensions and description of your own image.

Sources & further reading

Examples and worksheets on this page are illustrative. Documentation links were checked in November 2026; follow the relevant product’s current instructions.