Image Optimization for the Web: Formats, Sizes and Habits That Matter

JPEG, PNG, WebP or AVIF? A practical guide to choosing formats, resizing, compressing and loading images so pages stay fast.

Photo editing software open on a laptop screen
Photo by Zulfugar Karimov on Unsplash

Images are usually the heaviest part of a web page. On a typical portfolio or business site, photos account for more than half of the bytes a visitor downloads, and the hero image is very often the element that decides how fast the page feels. The good news: image optimization is mostly a matter of a few repeatable habits.

1. Pick the right format

Format Best for Notes
JPEG Photographs, when compatibility matters most Universal, but larger than newer formats
PNG Screenshots, graphics needing transparency Lossless, so files can be large
WebP Almost everything on the web Typically 25 to 35 percent smaller than JPEG at similar quality; supported by all modern browsers
AVIF Photos where every kilobyte counts Often smaller still, but slower to encode
SVG Logos, icons, simple illustrations Vector, tiny and sharp at any size

2. Resize before you upload

A camera or stock photo can be 4000 pixels wide or more. If your content column is 800 pixels wide, nobody benefits from the extra pixels. A reasonable rule: export at no more than twice the largest display width (to cover high-density screens), and cap full-width hero images at around 1600 to 2000 pixels.

3. Compress sensibly

For photographs, a quality setting between 75 and 85 is usually visually indistinguishable from the original while being a fraction of the size. Look at the result at normal viewing size instead of zooming in to 400 percent. Tools that work well include Squoosh in the browser, ImageMagick or cwebp on the command line, and plugins that compress on upload.

4. Serve different sizes to different screens

The srcset and sizes attributes let the browser choose the smallest suitable file for the visitor’s screen. WordPress generates several sizes for each upload and adds these attributes automatically, as long as your theme uses the standard image functions.

5. Set width and height

Always include the intrinsic width and height of an image. The browser then reserves the right amount of space before the file arrives, which prevents the page from jumping (layout shift).

6. Lazy-load the right images

Add loading="lazy" to images that start below the first screen so they are fetched only when needed. Do not lazy-load the main hero image; it should be requested immediately, because it is usually the largest contentful paint element.

7. Write real alt text

Alt text describes the image for people using screen readers and for search engines. Describe what is shown and why it matters in a short phrase. Decorative images can have an empty alt attribute. This costs nothing in speed and helps accessibility and SEO.

8. Use meaningful file names

n8n-workflow-diagram.webp says more than IMG_4021.webp. Lowercase words separated by hyphens are the convention.

A simple workflow

  1. Choose the photo and crop it to the shape you need.
  2. Resize to the maximum display width, doubled for sharp screens.
  3. Export as WebP at quality around 80.
  4. Name the file descriptively.
  5. Upload, add alt text, and check that width and height are set.
  6. Test the page in PageSpeed Insights and look at the “properly size images” and “next-gen formats” audits.

Key takeaways

Resize, compress, use WebP, describe the image, and load it at the right moment. Doing these five things consistently often cuts page weight by half or more without any visible loss in quality.

Leave a Reply

Your email address will not be published. Required fields are marked *