How to optimize images for a website
A useful image budget starts with a specific layout. A full-width feature photograph, a grid thumbnail and a company logo have different jobs and deserve different exports.
Measure the image slot
Inspect the layout at phone and desktop widths. A card that occupies 320 CSS pixels may benefit from a 640-pixel source on a two-times-density screen. Export a few widths that match the real layouts. Use srcset and sizes in your HTML so the browser can select a suitable download.
Choose the lightest acceptable file
Compare JPG and WebP or AVIF on photos at the exact delivery dimensions. For icons and screenshots, examine edge sharpness and transparency. Check the largest image first. Saving 300 KB on an article photograph usually matters more than saving one kilobyte on an icon.
Reserve space and measure the page
Give images width and height attributes or a stable aspect ratio so text stays in place while photographs arrive. Load images farther down the page lazily. Let the main image near the top load promptly. In browser developer tools, disable the cache and test a narrower viewport to confirm the expected resource actually downloads.