Market
Pricing
Sign inStart
Field GuideCSS and web
CSS and web

Optimise images for the web without losing quality

Images are usually the heaviest part of a page and the reason Lighthouse complains. Here is a working method: the right pixel sizes, the right format, responsive markup and loading hints, without visible loss.

GradientlyVerified Gradiently account·October 1, 2026·6 min read
Cover: Brass Reflection · GR·TC7D·AH

The short version

  • To optimize images for web, export each image at the size it is displayed, roughly doubled for high density screens, rather than uploading the original.
  • AVIF and WebP produce much smaller files than JPEG and PNG at similar visual quality, and every current browser supports WebP.
  • The srcset and sizes attributes let the browser download the smallest image that still looks sharp on each screen.
  • Lazy load images below the fold with loading="lazy", but load the main hero image eagerly with fetchpriority="high", because it usually decides Largest Contentful Paint.
  • Always set width and height on images so the browser reserves space and the layout does not jump while they load.
On this page
Step 1: export at the size you displayStep 2: choose the right formatStep 3: compress, then lookStep 4: responsive markup with srcset and sizesStep 5: loading hints that matterA checklist before you publish

To optimize images for web without visible loss, do five things: export each image at the pixel size it is displayed (about twice that for sharp screens), choose a modern format such as AVIF or WebP, compress to a moderate quality and compare by eye, serve several sizes with srcset, and lazy load anything below the fold. Those steps clear most of the image warnings in Lighthouse and usually cut page weight dramatically, because the original photo straight from a camera or design tool is many times larger than the screen needs.

Step 1: export at the size you display

An image shown 800 pixels wide does not need to be 4,000 pixels wide. Lighthouse flags oversized images because the extra pixels are downloaded, decoded and thrown away. Measure how wide the image appears in your layout at its largest, then export at roughly twice that width for high density phones and laptops. Going beyond two times rarely looks sharper and always costs bytes.

Full width hero

Displayed at

Up to 1920 px

Export width

1920 px, plus smaller versions
Article image

Displayed at

About 720 px

Export width

1440 px
Card thumbnail

Displayed at

About 360 px

Export width

720 px
Avatar48 px

Export width

96 px
Open Graph image

Displayed at

Off site

Export width

1200×630 exactly
ImageDisplayed atExport width
Full width heroUp to 1920 px1920 px, plus smaller versions
Article imageAbout 720 px1440 px
Card thumbnailAbout 360 px720 px
Avatar48 px96 px
Open Graph imageOff site1200×630 exactly
Typical targets. A full width hero is the exception to doubling: 1920 px covers most screens, and very large displays get a slightly soft image at a sensible cost.

Website hero 1920×1080

1920 × 1080

Blog banner 1200×600

1200 × 600

Link preview 1200×630

1200 × 630

Three common web image sizes drawn to scale. Design at the final size so nothing is cropped or scaled after export.

Step 2: choose the right format

Format matters more than any compression slider. AVIF usually gives the smallest file, WebP comes close and is supported everywhere current, and JPEG and PNG remain the safe fallbacks. WebP vs PNG and PNG vs JPG go deeper on each pair.

AVIFPhotos, gradients, large heroes

Notes

Smallest files; slower to encode
WebPAlmost everything

Notes

Lossy and lossless, transparency, wide support
JPEGPhotos, as a fallback

Notes

No transparency; bands on smooth gradients
PNGScreenshots, flat graphics, transparency

Notes

Lossless and large for photos
SVGLogos, icons, illustrations

Notes

Vector, tiny when simple; see SVG vs PNG
FormatBest forNotes
AVIFPhotos, gradients, large heroesSmallest files; slower to encode
WebPAlmost everythingLossy and lossless, transparency, wide support
JPEGPhotos, as a fallbackNo transparency; bands on smooth gradients
PNGScreenshots, flat graphics, transparencyLossless and large for photos
SVGLogos, icons, illustrationsVector, tiny when simple; see SVG vs PNG
Pick by content, not habit. Smooth gradients are the hardest case for JPEG, which is where WebP and AVIF help most.

Gradients compress badly

Smooth colour transitions show compression as visible steps. Add a little grain before exporting, as described in gradient banding, and the encoder can work harder without anyone seeing it. Better still, draw web gradients in CSS.

A hero gradient in about 70 byteslinear-gradient(160deg, #0f172a 0%, #1e3a8a 50%, #0ea5e9 100%)
This gradient, as CSS, costs less than a single line of the page. Exported as a 1920×1080 image, the same thing would weigh many kilobytes. See CSS gradient performance.

Step 3: compress, then look

Lossy formats have a quality setting, and the right value depends on the image. Start around 75 to 80 for WebP and around 50 to 60 for AVIF, export, and compare against the original at 100% zoom. Lower it until you can see a difference, then step back up once. Faces, fine text and gradients need more quality than busy landscapes. Image compression explains what the encoder throws away.

Strip metadata such as camera details and embedded thumbnails while you are there. Most export tools do it with one checkbox, and it removes bytes nobody sees.

Step 4: responsive markup with srcset and sizes

With several widths exported, let the browser pick. srcset lists the files and their widths; sizes tells the browser how wide the image will appear. The browser then downloads the smallest file that is sharp enough for that screen.

html
<picture>
  <source type="image/avif"
    srcset="/img/hero-960.avif 960w, /img/hero-1440.avif 1440w, /img/hero-1920.avif 1920w"
    sizes="100vw" />
  <source type="image/webp"
    srcset="/img/hero-960.webp 960w, /img/hero-1440.webp 1440w, /img/hero-1920.webp 1920w"
    sizes="100vw" />
  <img src="/img/hero-1920.jpg" alt="Morning light over the harbour"
    width="1920" height="1080" fetchpriority="high" decoding="async" />
</picture>
The browser uses the first source it supports. The img element is both the fallback and the place for alt, width, height and loading hints.

For an image inside a column, describe the layout in sizes, for example sizes="(min-width: 1024px) 720px, 100vw". Getting sizes wrong is the most common reason a responsive setup still downloads the big file.

Step 5: loading hints that matter

html
<!-- Below the fold: let the browser wait -->
<img src="/img/team-720.webp" alt="The team at the spring workshop"
  width="720" height="480" loading="lazy" decoding="async" />

<!-- The hero: fetch first, never lazy -->
<img src="/img/hero-1920.webp" alt="Morning light over the harbour"
  width="1920" height="1080" fetchpriority="high" />
Width and height let the browser reserve space from the aspect ratio, so nothing shifts as images arrive. CSS can still make the image fluid with max-width: 100% and height: auto.

Common mistakes

  • loading="lazy" on the hero image
  • No width and height, so the page jumps
  • One huge file for every screen
  • A JPEG of a flat logo or screenshot
  • Gradient backgrounds saved as images

Instead

  • Hero loads eagerly with fetchpriority="high"
  • Set both attributes on every img
  • srcset with three or four widths
  • SVG or PNG for flat graphics
  • CSS gradients, with grain if needed

These hints map directly to Core Web Vitals. The hero image is often the Largest Contentful Paint element, which web.dev suggests should render within 2.5 seconds, and missing dimensions are a classic cause of layout shift. If your hero is a video rather than an image, the same thinking applies in video backgrounds for websites.

A checklist before you publish

  1. 1

    Measure the slot

    Find the largest displayed width of each image in your layout.

  2. 2

    Export at the right sizes

    One to two times the slot width, plus smaller versions for phones.

  3. 3

    Pick the format

    AVIF or WebP for photos and gradients, SVG for logos, PNG only when it wins.

  4. 4

    Compress by eye

    Lower quality until you see a change, then raise it a step.

  5. 5

    Mark it up

    srcset, sizes, width, height, alt, and lazy loading below the fold.

  6. 6

    Test it

    Run Lighthouse in an incognito window and check the image audits and LCP element.

Much of this is easier when the image is made at its final size in the first place. In Gradiently you design once and Pro resizes to every size in one step, then exports PNG, JPG or SVG at exact dimensions up to 4K, so the hero, the banner and the Open Graph image each start at the size the page will show.

Design with a living gradient

Posts, stories, slides and banners in every size, with text that always reads.

Start designing, free

Questions people ask

How do I optimize images for web without losing quality?

Export at the displayed size, use AVIF or WebP, lower the quality setting only until you can see a difference, and serve several sizes with srcset. Most visual loss comes from heavy compression, not from resizing.

What is the best image format for websites?

WebP is the safe modern default and AVIF is usually smaller still. Use SVG for logos and icons, and keep JPEG or PNG as fallbacks.

Should I lazy load all images?

No. Lazy load images below the fold, but load the main hero image eagerly, because delaying it slows Largest Contentful Paint.

What size should website images be?

About twice the width they are displayed at, for sharp high density screens. A full width hero at 1920 px covers most displays.

Why does Lighthouse say my images are not properly sized?

The file has more pixels than the space it fills on the page. Export a smaller version and use srcset and sizes so the browser picks the right one.

Share this guide

Written by GradientlyVerified Gradiently account

The team behind Gradiently, a design tool built around Marks: living gradients that make everything you design look like yours.

See our profile

On this page

Step 1: export at the size you displayStep 2: choose the right formatStep 3: compress, then lookStep 4: responsive markup with srcset and sizesStep 5: loading hints that matterA checklist before you publish

Share this guide

Next in CSS and web

Open Graph tags: the complete guide for share previews

Keep reading

All CSS and web guides
CSS and web

WebP vs PNG and JPG: modern formats for the web

5 min read

Your website does not have to serve the same files you post to Instagram. WebP and AVIF do the same job as PNG and JPG in fewer bytes, if you set them up properly.

CSS and web

Image compression without ruining gradients

5 min read

Photos survive heavy compression. Gradients do not. Here is why a smooth blend turns into stripes, and the exact settings that keep it smooth while the file stays small.

CSS and web

PNG vs JPG: which image format to use and when

6 min read

One format keeps every pixel, the other throws detail away to stay small. Knowing which detail gets thrown away tells you which to pick, every time.

Find the look that’s only yours.

Every Mark is a living background with one owner. Try an unclaimed Mark, and claim yours when it feels right.

Start designing

Check a certificate

Type a certificate number or a Mark’s code to see who owns it.

Works with ChatGPT and Claude

Ask your AI for a design. It makes it in your Mark, ready to edit.

ChatGPTClaude
How to connect

Product

  • Market
  • Explore
  • Pricing
  • Certificates

Learn

  • Field Guide
  • Help centre
  • What’s new

Developers

  • Overview
  • ChatGPT and Claude
  • API reference
  • API keys

Company

  • About
  • Contact us
  • Sign in

Legal

  • Terms
  • Privacy
  • Refunds
  • Mark protection
  • Cookies
  • All policies
Move through the letters. Each one wears a real Mark.Touch a letter to see its Mark.One name. Ten Marks inside it.
© 2026 Gradiently