Images can make a website more useful, attractive and easier to understand, but they can also account for a large share of the data a browser must download. Serving a very large photograph to a small mobile screen, using an unnecessarily heavy format, or loading every image as soon as a page opens can waste bandwidth and delay the content people came to see.
Website image optimization is the process of delivering images at the right dimensions, in an efficient format and at an appropriate quality for each device and context. It includes compression, responsive image markup, careful lazy loading, stable dimensions, descriptive alternative text and measurement. The goal is not to make every image as small as possible. It is to preserve useful visual quality while avoiding unnecessary bytes and delays.
The practical rule
Resize an image for the largest size it will actually be displayed, compress it without visible damage, offer a modern format with a sensible fallback, and do not lazy-load the main image that makes up the page’s Largest Contentful Paint element.
Why website image optimization matters
An image that is 2,400 pixels wide may look excellent on a desktop display, but it is often wasteful when shown at 360 CSS pixels on a phone. The browser may have to download far more image data than the layout needs. A poorly optimized hero image can delay the main visible content, while images without reserved dimensions can make text and buttons move as the page loads.
- Faster loading: smaller, appropriately sized files reduce the amount of data transferred before an image can be displayed.
- Better mobile experience: responsive image delivery prevents small screens from downloading unnecessarily large desktop assets.
- More stable layouts: declared image dimensions help the browser reserve space and reduce unexpected movement.
- Lower data usage: efficient images are helpful for visitors on mobile connections and limited data plans.
- Better accessibility: meaningful alternative text communicates the purpose of informative images to people using screen readers.
- Image discovery: descriptive context, crawlable HTML image elements and good landing-page content help search engines understand images.
Image optimization is one part of a wider performance strategy. Our Core Web Vitals optimization guide explains how loading, interaction and layout stability fit together. For a broader performance checklist, see how to improve website speed. Our mobile optimization guide covers responsive layouts and mobile usability.
Choose the right image format: JPEG, PNG, WebP, AVIF or SVG
No single format is best for every image. Photographs, logos, illustrations and interface icons have different requirements. Choose a format based on visual content, transparency needs, browser support, editing workflow and the delivery options available on your site.
| Format | Best suited to | Strengths | Considerations |
|---|---|---|---|
| JPEG / JPG | Photographs and complex images without transparency. | Broad compatibility and adjustable lossy compression. | Can be larger than newer formats at a similar visual quality; repeated editing and saving can degrade quality. |
| PNG | Screenshots, graphics with sharp edges and images requiring transparency. | Lossless compression and alpha transparency. | Often unnecessarily large for photographic images. |
| WebP | Photographs, graphics and many images with transparency. | Supports lossy and lossless compression, transparency and animation. | Keep an original master and test the result for fine detail, text and gradients. |
| AVIF | Photographs and complex images where smaller delivery size is valuable. | Can deliver high visual quality at low file sizes and supports transparency and HDR features. | Encoding can take more processing time. Check your audience’s browser support and image pipeline. |
| SVG | Logos, icons, diagrams and simple vector artwork. | Scales cleanly at different sizes and is often compact for simple shapes. | Not a replacement for photographic formats. Sanitize and trust SVG sources because SVG can contain active content. |
WebP and AVIF are useful modern choices, but conversion alone does not guarantee a smaller or better image. A detailed photograph, a flat illustration and a transparent logo may behave differently. Compare the resulting files at the actual display size and check that edges, text, gradients and fine textures still look acceptable.
WebP vs AVIF: which should you use?
WebP is a practical default for many websites because it combines broad browser support with lossy and lossless compression and transparency. AVIF can reduce image size further in many situations, particularly for photographic content, but it may require more CPU time to encode and an intentional fallback strategy.
For most sites, the choice should be based on the real image library and visitor experience rather than a universal claim that one format always wins. A useful workflow is to keep a high-quality original, generate WebP and AVIF variants where the tooling supports them, and test the formats on representative phones and desktop browsers.
A sensible format strategy
Use AVIF where it is supported and offers a meaningful size or quality improvement, provide WebP as a widely supported modern alternative, and retain a JPEG or PNG fallback when needed. For logos and icons, consider SVG when vector artwork is appropriate.
Compress images without making them look poor
Compression reduces the amount of data required to represent an image. Lossy compression removes some information to reduce file size, while lossless compression preserves the original pixel data. The right choice depends on the image and how it will be used.
Use these practices to avoid delivering oversized files:
- Resize the image before uploading it. Do not upload a 5,000-pixel original when the largest rendered version is only 1,200 pixels wide.
- Choose lossy compression for most photographs, then inspect details such as faces, hair, foliage, gradients and small text.
- Use lossless compression when exact pixel preservation matters, such as some screenshots, charts or interface assets.
- Remove metadata that is not needed for the page, while retaining copyright or attribution information when required.
- Generate a few practical size variants instead of many nearly identical files that are difficult to manage.
- Compare the compressed file with the original at the size visitors will actually see, not only at 300% zoom.
There is no universal quality percentage or file-size target for every image. A photographic hero, a small thumbnail and a logo have different visual requirements. Use a consistent starting preset in your image tool, then adjust by inspecting the results and measuring the transferred bytes.
Resize images to match their displayed dimensions
Image dimensions and file size are related but not interchangeable. A highly compressed image can still be unnecessarily large in pixel dimensions. Likewise, a small image stretched across a wide screen may look blurry even when the file is compact.
Start by checking the actual rendered size of images in your page templates. If a content image is displayed at around 760 pixels wide on desktop, serving a 4,000-pixel original may not be useful. On high-density screens, the browser may choose a larger source from the responsive set, so provide a sensible range of variants rather than one tiny image.
| Image placement | What to prepare | What to check |
|---|---|---|
| Small thumbnail | A small derivative close to the card’s rendered size. | Avoid downloading the original full-size image for a tiny card. |
| Article content | Medium and larger versions to suit the content column and higher-density screens. | Keep the image sharp at its normal display size. |
| Hero or banner | A carefully compressed large variant, with a mobile crop if the composition needs it. | Prioritize the true LCP image; do not lazy-load it. |
| Logo or icon | A vector SVG or appropriately sized transparent raster asset. | Check clarity, transparency and safe source handling. |
Serve responsive images with srcset and sizes
Responsive images let the browser choose from several versions of the same image based on the layout and display conditions. The srcset attribute lists available file variants, while sizes describes the approximate width the image will occupy in the layout. The browser can then select a suitable source before downloading it.
Here is a simplified example. It assumes that your image processing system has created 480-, 800- and 1,200-pixel-wide files:
<img
src="/images/landscape-800.webp"
srcset="
/images/landscape-480.webp 480w,
/images/landscape-800.webp 800w,
/images/landscape-1200.webp 1200w"
sizes="(max-width: 600px) 100vw,
(max-width: 1000px) 90vw,
800px"
width="1200"
height="800"
alt="Mountain lake surrounded by pine forest">
The sizes values should reflect your actual layout. If the content column is only 720 pixels wide on desktop, do not tell the browser that the image fills a 1,200-pixel slot. Incorrect size hints can cause browsers to select larger images than necessary.
Use the picture element for format fallback and art direction
The picture element is useful when you want to offer different formats or different crops for different screen sizes. Put the preferred sources first and include a normal img element as the fallback. Always include useful alternative text and dimensions on the fallback image.
<picture>
<source
type="image/avif"
srcset="/images/hero-800.avif 800w,
/images/hero-1200.avif 1200w"
sizes="(max-width: 700px) 100vw, 1100px">
<source
type="image/webp"
srcset="/images/hero-800.webp 800w,
/images/hero-1200.webp 1200w"
sizes="(max-width: 700px) 100vw, 1100px">
<img
src="/images/hero-1200.jpg"
width="1200"
height="700"
alt="A wide view of the product workspace">
</picture>
Use picture with a media condition when you need a different crop or composition on mobile, not just a smaller copy of the same photograph. For simple resolution switching, srcset and sizes on img are usually enough. Keep the fallback src so browsers and crawlers have a standard image URL to use.
Lazy-load below-the-fold images, not the main visual
Lazy loading defers the download of an image until the browser estimates that it is approaching the visible area. It can reduce unnecessary downloads on long pages, galleries and article pages with many images. Modern browsers support native lazy loading through the loading attribute, so a separate JavaScript library is not always necessary.
Use loading="lazy" for images that are below the initial viewport. Do not apply it indiscriminately to every image. In particular, the hero or other image that is likely to be the Largest Contentful Paint element should normally load eagerly. Lazy-loading the main visual delays its discovery and can make LCP worse.
<!-- Main image visible when the page opens -->
<img
src="/images/page-hero.webp"
width="1200"
height="700"
fetchpriority="high"
alt="Team reviewing a website performance report">
<!-- Image further down the page -->
<img
src="/images/related-guide.webp"
width="800"
height="520"
loading="lazy"
decoding="async"
alt="Website audit checklist on a laptop screen">
Use fetchpriority="high" selectively when you have identified an important image that is likely to be the LCP element. Do not assign high priority to every image: doing so removes the browser’s ability to distinguish what matters most. Measure before and after changes using real page loads and a performance test.
Set width and height to prevent layout shifts
Browsers need to know how much space an image will occupy before it finishes downloading. Include its intrinsic width and height attributes whenever possible. The browser can calculate the aspect ratio and reserve a layout box, reducing the chance that text or buttons jump when the image appears.
<img
src="/images/article-photo.webp"
width="1200"
height="800"
alt="A designer editing a website layout">
Use CSS to make images fluid while preserving their proportions:
img {
max-width: 100%;
height: auto;
}
For cards or galleries that require a fixed visual frame, use a deliberate aspect ratio and an appropriate object-fit rule. Do not force every photograph into the same crop if doing so cuts off important information.
Write useful alt text and descriptive image names
Alternative text describes the information or function an image adds to the page. It helps people who use screen readers understand meaningful images when they cannot see them. It can also help search engines interpret the image, but it should be written for people first.
- Describe what matters in the image in the context of the surrounding content.
- Keep the description concise and specific. Avoid unnecessary phrases such as “image of” or “picture of”.
- For a linked image or button, describe the action or destination when that is its purpose.
- Use an empty
alt=""for decorative images that do not add information, so assistive technologies can skip them. - Do not stuff keywords into alt text or repeat the same generic description across every image.
- Use descriptive filenames such as
responsive-image-srcset-example.webprather thanIMG_0492.webp, when practical.
Google recommends using standard HTML image elements and relevant surrounding page content to help it discover and understand images. Do not rely only on CSS background images for important content that you want search engines and assistive technologies to understand.
Optimize images in WordPress
WordPress can generate multiple image sizes for an uploaded image and can output responsive image attributes such as srcset and sizes in supported contexts. Themes, plugins and custom templates can change the final markup, so inspect the rendered page rather than assuming every image is being served responsively.
Use this workflow for a WordPress site:
- Prepare the source image. Crop and resize it for its intended placement before uploading. Keep an original master outside the delivery pipeline.
- Choose a modern output format. Use WebP or AVIF when your host and delivery stack support it, and confirm that a suitable fallback is available where needed.
- Review generated sizes. Check the Media Library and the HTML source to confirm WordPress or your image plugin creates sensible thumbnail, medium and large variants.
- Check responsive markup. Inspect an image element to see whether it includes
srcset,sizes, width, height and meaningful alt text. - Audit lazy loading. Confirm that below-the-fold images are deferred, while the visible hero or LCP image is not accidentally lazy-loaded.
- Check the cache and CDN. Purge the relevant caches after changing image delivery rules, then verify that new formats and resized variants are served correctly.
- Test important templates. Check the homepage, category archive, single article, product page and any landing pages separately. Different templates may output different image markup.
In WordPress, do not install multiple image optimization plugins that perform the same conversion or rewriting functions without checking for conflicts. Decide which system generates variants, which system delivers the modern format and which system handles lazy loading. Test one change at a time so you can identify problems such as broken image URLs, duplicate transformations or missing thumbnails.
Tools to test and optimize website images
Use a combination of image inspection and page-level testing. A compressed file is not automatically a faster page if it is loaded too early, requested in the wrong size or blocked by another resource.
| Tool | Best use | What to inspect |
|---|---|---|
| PageSpeed Insights | Page-level performance and Core Web Vitals diagnostics. | Image sizing, LCP element, unused bytes and field data where available. |
| Chrome DevTools | Network requests, image dimensions, priority and loading sequence. | Which image downloads, its transfer size, format and whether it is discovered early. |
| Squoosh | Comparing image formats and compression settings. | Visual quality against output size before using a setting for many images. |
| ImageMagick | Batch resizing, format conversion and repeatable image processing. | Output dimensions, file size, image orientation and conversion quality. |
| Google Search Console | Monitoring search performance and page experience signals over time. | Relevant indexing or page experience reports and changes after deployment. |
Test representative pages on both desktop and mobile. Use the same URL and similar test conditions before and after an optimization. Lab tests help diagnose a page, while real-user field data reflects the devices, networks and usage patterns of actual visitors.
A practical website image optimization checklist
- Choose JPEG, PNG, WebP, AVIF or SVG based on the image type.
- Resize images to match their real display dimensions.
- Compress photographs and graphics while checking visual quality.
- Provide responsive variants and accurate
srcsetandsizeshints. - Use
picturewhen format fallback or a different mobile crop is needed. - Include a normal fallback
srcand meaningful alt text. - Set image width and height to reserve layout space.
- Lazy-load images below the first viewport, not the LCP image.
- Use high fetch priority only for the genuinely important main image.
- Verify the final HTML, network requests, CDN behavior and cached variants.
- Re-test key templates after theme, plugin or image pipeline changes.
Common image optimization mistakes
- Converting everything to one format: photographs, transparent logos and diagrams have different requirements. Pick a format for the content.
- Uploading huge originals for small placements: create appropriately sized derivatives and let the browser choose.
- Lazy-loading the hero image: this can delay the LCP resource and make the most prominent visual appear later.
- Lazy-loading every image without exceptions: images already visible when the page opens should normally load eagerly.
- Forgetting width and height: missing dimensions can cause layout shifts as images arrive.
- Using incorrect sizes hints: inaccurate
sizesvalues may cause the browser to download an image that is larger than the displayed slot needs. - Removing fallback sources: keep the standard
srcon the image element and use progressive enhancement for modern formats. - Writing keyword-stuffed alt text: describe the image accurately instead of repeating search phrases.
- Testing only the homepage: archives, article templates and landing pages may have different image behavior.
- Trusting a plugin without checking its output: verify actual network requests and HTML after enabling optimization features.
Frequently asked questions
Is WebP better than JPEG?
WebP can often provide smaller files than JPEG at comparable visual quality and also supports transparency. JPEG remains widely compatible and can still be appropriate in some workflows. Compare the actual output for your images rather than assuming every conversion will improve the result.
Is AVIF better than WebP?
AVIF can provide excellent compression and may produce smaller files for many photographs, but results vary by image and encoding settings. WebP is a practical modern format with broad support. Test both using your own images, browser audience and server-side delivery pipeline.
Should I convert PNG images to WebP?
It depends on why the PNG was used. Photographic PNG files may become much smaller when converted to a lossy modern format. Screenshots, logos and graphics with sharp text or transparency need a careful quality check. Keep SVG for suitable vector artwork.
Should I lazy-load all images on a page?
No. Lazy-load images that are below the initial viewport and likely to be needed only after scrolling. Keep the main visible image, especially the likely LCP image, eager-loaded so it can be discovered early.
What are srcset and sizes used for?
srcset lists multiple image files at different widths or pixel densities. sizes tells the browser approximately how wide the image will appear in the layout. Together, they help the browser select a source that suits the device and rendered size.
Do image dimensions affect Core Web Vitals?
Yes. Declaring width and height helps the browser reserve space and reduces unexpected layout movement, which supports CLS. The size, discoverability and loading priority of a main image can also affect LCP.
Does image optimization improve SEO?
It can improve the user experience and support page performance, but it does not guarantee rankings. Use crawlable HTML image elements, descriptive alt text, relevant nearby content and appropriate image delivery. Google’s image guidance explains additional discovery and indexing considerations.
Which image optimization tool should I use?
For a small number of images, Squoosh is useful for comparing formats and compression settings. For repeatable or large-scale processing, use a controlled server-side pipeline or a trusted image service. Test the result using PageSpeed Insights and browser developer tools.
Official sources and further reading
These documentation pages explain image discovery, responsive delivery, browser loading behavior and LCP optimization. Check them when implementing image changes because browser behavior and platform tooling can evolve.
| Source | What it explains | Reference |
|---|---|---|
| Google Search Central | Image discovery, HTML image elements, responsive images, alt text and image landing-page context. | Google image SEO best practices ↗ |
| MDN Web Docs | Responsive image markup, srcset, sizes and the picture element. |
Using responsive images in HTML ↗ |
| web.dev | Browser-level lazy loading and guidance on image dimensions and above-the-fold images. | Browser-level image lazy loading ↗ |
| web.dev | Discovering and prioritizing the LCP resource, including avoiding lazy loading for the main image. | Optimize Largest Contentful Paint ↗ |
| web.dev | Responsive image sizing, fluid image behavior and screen-specific delivery. | Responsive images ↗ |
| Squoosh | A browser-based tool for comparing image encoders and compression results. | Squoosh image optimizer ↗ |
Effective website image optimization combines the right source dimensions, a suitable modern format, careful compression and browser-aware delivery. Make the main visual easy to discover, defer images that are genuinely off-screen, reserve their layout space and describe informative images clearly. Measure the result on real templates and real devices, then keep the process consistent as your website grows.