The Definitive Guide to Image Optimization: Fix Largest Contentful Paint (LCP) and Achieve 90+ PageSpeed



Images are the backbone of the modern web, driving engagement, conveying complex information instantly, and building brand identity. Yet, they are also the single greatest contributor to website bloat, often accounting for more than half of a page’s total weight. This inefficiency directly impacts the user experience and, critically, your search engine rankings through Core Web Vitals (CWV). The most prominent of these vitals is the Largest Contentful Paint (LCP), which measures how quickly the main content of a page is loaded and rendered for the user. A slow LCP, often caused by an unoptimized hero image or banner, can torpedo your PageSpeed score and lead to higher bounce rates.

Achieving a PageSpeed Insights score of 90 or above is no longer a goal for perfectionists—it is a baseline requirement for a competitive website in the current digital landscape. This definitive, step-by-step guide provides a comprehensive technical roadmap to transform your image handling, ensuring fast load times, superior visual quality, and a PageSpeed score that is firmly in the ‘green’ zone. We will cover everything from selecting the next-generation image format to implementing advanced HTML techniques that dictate how and when the browser loads your most important visual assets.

Understanding the Largest Contentful Paint (LCP) and Image Dependency

To optimize for speed, you must first understand the metric you are trying to improve. Largest Contentful Paint (LCP) is a Core Web Vitals metric that reports the render time of the largest image or text block visible within the viewport. To pass the CWV assessment, a page should strive to have its LCP occur within the first 2.5 seconds of the page starting to load for at least 75% of users. The reality for many websites is that the LCP element is almost always an image—specifically, the hero image, the main product photo, or the large banner directly below the navigation bar.

The speed at which this LCP element loads is a direct function of four primary factors:

  • Slow Server Response Time (TTFB): If the server takes too long to respond with the initial HTML document, everything else is delayed, including the browser’s discovery of the LCP image. Optimization here starts with better hosting and effective caching strategies.
  • Render-Blocking Resources: Large CSS or JavaScript files that must be downloaded and parsed before the browser can render content can significantly push back LCP. Removing or deferring non-critical assets is key.
  • Resource Load Time: This is where image optimization has its greatest impact. A massive, high-resolution JPEG file will take substantially longer to download, especially on a slower mobile connection, compared to a correctly sized and modern-format image.
  • Client-Side Rendering: Using JavaScript to inject images into the Document Object Model (DOM) is a major anti-pattern for LCP. The browser cannot even begin downloading the image until the script has executed, creating an unnecessary and costly delay.

Because the resource load time of the LCP image is the easiest and most direct factor to control, a systematic approach to image optimization can yield the fastest and most substantial gains in your PageSpeed score.

Step 1: Implementing Next-Generation Image Formats (WebP and AVIF)

The first and most impactful step in reducing image resource load time is migrating away from outdated formats like JPEG and PNG. Modern image formats offer significantly better compression with no discernible loss in visual quality, leading to substantial file size reductions. For the same quality level, WebP files are typically 25% to 35% smaller than comparable JPEGs, and AVIF can be 20% to 50% smaller than WebP.

The Advantages of WebP and AVIF

  • WebP: The Modern Workhorse. Developed by Google, WebP supports both lossy (like JPEG) and lossless (like PNG) compression, as well as transparency and animation. With over 96% browser support across all modern platforms, it should be the default format for nearly all raster images on your site. The file size reduction immediately translates into a faster image download time, directly improving LCP.
  • AVIF: The Cutting Edge. AVIF (AV1 Image Format) utilizes the high-efficiency AV1 video codec. It provides superior compression to WebP, often yielding the smallest file sizes at the same perceived quality. Browser support is strong (Chrome, Firefox, Safari 16+, Edge), making it excellent for high-traffic or resource-intensive images, though the encoding process can take longer.
  • JPEG/PNG: The Fallback. Standard JPEG is still necessary as the final fallback for the small fraction of older browsers that do not support WebP or AVIF. PNG is reserved almost exclusively for images that require true transparency or non-photographic graphics with sharp, clean lines (like logos or icons).

Serving Modern Formats with the <picture> Element

The key to using modern formats without sacrificing backward compatibility is the HTML picture element. This element allows you to specify multiple image sources, and the browser will automatically select the first source it supports, falling back to the standard img element if none of the modern formats are supported.

<picture> <source srcset="hero-image.avif" type="image/avif"> 
<source srcset="hero-image.webp" type="image/webp"> 
<img src="hero-image.jpg" alt="Description of the hero image" width="1200" height="800"> 
</picture>

In this example, a browser that supports AVIF loads the smallest, most efficient file first. If it supports WebP but not AVIF, it skips the first line and loads the WebP file. If it supports neither (a rarity today), it defaults to the standard JPEG in the img tag. This process is automatic and highly efficient, ensuring all users get the best possible performance.

Step 2: Mastering Image Resolution and Compression

Even with the best formats, serving an image that is physically too large for the user’s screen is wasteful. An image that displays at 400 pixels wide on a mobile screen should not be a 4000-pixel wide file. This is a crucial element of optimization known as resizing and compression.

The Power of Resizing: Correctly Sizing Your Images

The principle here is simple: Never serve an image that is larger than its display size. The browser should not have to download a massive file only to shrink it down using CSS or HTML. For a PageSpeed score above 90, you must identify the maximum container size for each image on your site and resize the original file to that exact dimension.

If your main content column is 800 pixels wide, the image you serve should be 800 pixels wide, not 2500 pixels. For high-resolution (Retina) screens, it is common practice to serve an image at 1.5x or 2x the display dimension to maintain sharpness, but anything beyond 2x is typically redundant.

Practical steps for resolution optimization:

  1. Identify Display Widths: Use your browser’s developer tools to measure the maximum width (in pixels) that your image will occupy on standard desktop and mobile viewports.
  2. Resize Originals: Use a graphics editor or a server-side image manipulation tool to create versions of your image at these necessary dimensions (e.g., 400px wide for mobile, 800px wide for tablet/desktop, and 1600px wide for high-resolution desktop).
  3. Avoid CSS Scaling: If you see a browser warning that an image is being resized by the CSS, it means you are downloading a bloated file. Fix the source image size, not the CSS.

Intelligent Compression: Lossy vs. Lossless

Compression reduces the file size while maintaining the same physical dimensions. There are two types:

  • Lossless Compression: This method preserves the image data exactly, meaning the decompressed image is pixel-for-pixel identical to the original. Tools like PNG use this for optimal quality, but the file size savings are modest, typically around 5% to 20%. It is best reserved for simple graphics or images where any loss of detail is unacceptable.
  • Lossy Compression: This method achieves maximum size reduction by selectively discarding redundant or less important visual information, such as small variations in color that the human eye cannot easily perceive. Formats like JPEG, WebP, and AVIF excel here. A quality setting between 70% and 85% is often the sweet spot, providing a massive reduction in file size (often 50-80%) with a negligible difference in visual quality. This should be the default choice for all photographic content.

You can use robust online services and APIs like TinyPNG (which supports WebP and JPEG/PNG) or ShortPixel to automate this process. These tools use sophisticated algorithms to achieve intelligent, multi-pass lossy compression that minimizes quality degradation while maximizing size reduction.

Step 3: Implementing Responsive Images with srcset and sizes

The next step in optimization is ensuring that the browser never downloads an image larger than it needs for the current user’s screen size and device resolution. This is achieved through the srcset and sizes attributes, which are paramount to resolving LCP issues on mobile devices.

The Role of srcset and sizes

The srcset attribute allows you to define a set of image sources along with their intrinsic widths (using the ‘w’ descriptor). The sizes attribute provides a set of media conditions and the corresponding width the image will occupy at that viewport size. The browser then takes this information—without having to download any image data—and intelligently chooses the optimal image from the srcset list.

<img src="default-800w.jpg" 
srcset="
image-400w.webp 400w, 
image-800w.webp 800w, 
image-1200w.webp 1200w" 
sizes="
(max-width: 600px) 100vw, 
(max-width: 1200px) 800px, 1200px" 
alt="An example of a fully responsive image" 
width="1200" height="800" >

Breaking down this critical piece of HTML:

  1. srcset: This lists the available WebP image files and their actual widths in pixels (e.g., image-400w.webp 400w).
  2. sizes: This tells the browser the physical slot size the image will occupy based on media queries. For instance, (max-width: 600px) 100vw means that on viewports up to 600px wide, the image will take up 100% of the viewport width.
  3. Browser Logic: If a user is on a standard mobile device (viewport < 600px) with a slow connection, the browser reads the sizes attribute, determines the image slot is 100vw (e.g., 375px), and then selects the smallest file from srcset that is an acceptable match (likely the 400w file), drastically reducing the LCP resource size.

Using srcset and sizes is non-negotiable for improving LCP on mobile, as it guarantees a user on a low-end device or limited network is not forced to download the massive desktop image.

Step 4: Prioritizing the Largest Contentful Paint (LCP) Resource

The challenge of LCP is not just about the image’s file size, but also about the time it takes for the browser to discover, download, and render it. The LCP image must be given top priority to ensure it loads before the 2.5-second threshold.

Preload and fetchpriority: Forcing the Front of the Line

The browser’s default loading sequence can sometimes delay critical resources. Two modern HTML attributes allow you to override this and explicitly signal the importance of the LCP image.

Using rel=”preload”

The link rel=”preload” tag, placed in the head of the HTML document, tells the browser to start downloading a critical resource (like the LCP image) immediately, even before the browser’s main parser has discovered it later in the HTML body. This is crucial when the LCP image is a background image defined in a CSS file, or if the resource is discovered late in the rendering process.

<head> 
... 
<link rel="preload" as="image" href="/path/to/hero-image.webp"> 
... 
</head>

Note that preloading should be used sparingly and only for resources that are essential to the initial viewport. Overusing preload can dilute its effectiveness by competing with other important resources.

The fetchpriority Attribute

A more targeted and efficient way to prioritize the LCP element is by using the fetchpriority=”high” attribute directly on the image tag. This hint tells the browser’s scheduler that this particular image is a high-priority resource and should be moved up in the download queue, relative to other resources that might be competing for bandwidth.

<img src="hero-image.jpg" alt="Hero image description" fetchpriority="high" width="1200" height="800" >

This simple attribute is particularly effective when the LCP is an img element and is a best practice recommended by Google’s performance team for the LCP candidate.

Step 5: The Crucial Role of Sizing Attributes and Decoding

Once the LCP image file has been downloaded, the browser must render it. Two final HTML attributes are essential to preventing layout shifts and speeding up the final painting step.

Preventing Layout Shifts with width and height Attributes

A primary cause of low Cumulative Layout Shift (CLS)—another Core Web Vital—is images loading without explicit dimensions. When an image loads, if the browser does not know its aspect ratio, it allocates zero space for it. Once the image data arrives, the browser suddenly allocates the necessary space, causing the content below it (like text or buttons) to jump down. This is the definition of a layout shift.

To fix this, always include the width and height attributes on the img tag. Even if the image is responsive (scaled by CSS), these attributes provide the browser with the original aspect ratio, allowing it to reserve the correct amount of space immediately. Your CSS can then use an aspect ratio box or simply height: auto; max-width: 100%; to manage the responsive scaling, but the initial dimensions must be present in the HTML.

<img src="optimized-image.webp" alt="Product detail" width="600" height="400" >

The decoding Attribute for Faster Rendering

The browser must perform a decoding process on an image after it is downloaded before it can be painted onto the screen. This process can be CPU-intensive. The decoding attribute provides a hint to the browser about how to handle this task.

For your LCP image, or any image that must be painted immediately:

  • decoding=”sync”: Suggests the browser should decode the image synchronously with other content, which can be useful for critical images like LCP candidates to ensure they are rendered as quickly as possible, though the effect can vary between browsers.
  • decoding=”async”: This is the ideal setting for all non-critical, off-screen images. It suggests the browser can decode the image in parallel on a separate thread, freeing up the main thread to handle user interaction and rendering of above-the-fold content. This is an excellent technique to reduce the main thread block time, which correlates with the Total Blocking Time (TBT) metric.

Step 6: Deferring Off-Screen Images with Lazy Loading

While the LCP image must be prioritized and loaded eagerly (loading=”eager”, which is the default), all images that appear “below the fold”—that is, outside the user’s initial viewport—should be deferred using lazy loading.

Native Lazy Loading: The loading=”lazy” Attribute

Native lazy loading is now a standard, supported feature in modern browsers, eliminating the need for complex JavaScript libraries for basic image deferral. By applying loading=”lazy” to any image that is not immediately visible, you instruct the browser not to download the image resource until the user scrolls near it.

<img src="product-gallery-image-3.webp" alt="Additional product view" loading="lazy" width="800" height="600" >

The benefit is twofold:

  1. Reduces Network Contention: By preventing dozens of off-screen images from being requested at once, you free up the limited network bandwidth for the critical resources that truly need it, especially the LCP image.
  2. Saves Data: If a user never scrolls to the bottom of the page, those images are never downloaded, saving their data and your bandwidth costs.

The only exception to this rule is the LCP image itself. Never lazy load the LCP image, as this will drastically increase its load time and destroy your PageSpeed score.

Step 7: Optimizing Images Delivered via CSS Backgrounds

Images applied using the CSS background-image property present a specific challenge: the browser cannot discover these image URLs until it has downloaded and processed the CSS file. This can delay the loading of the LCP if the LCP element is a CSS background image on your hero container.

Inline Critical CSS and Preload for Background Images

If the LCP element is a background image, you must take special steps to ensure its fast discovery:

  • Use HTML <img> Instead: The simplest and most performant solution is to re-engineer the page to use a standard <img> tag for the LCP image, which is easier for the browser to discover and prioritize.
  • Preload the Image: If using a background image is unavoidable, you must use the link rel=”preload” tag in the HTML head to tell the browser to download the image resource before the CSS file is fully parsed, as demonstrated earlier.
  • Inline Critical CSS: You can also inline the small portion of CSS required to define and display the LCP background image directly into a <style> tag within the HTML head. This allows the browser to discover the image URL without waiting for the external CSS file to download. All non-critical CSS should remain in external files.

Implementing Responsive Background Images

Unlike the <img> tag, CSS does not natively support the srcset and sizes attributes for resolution switching. To serve responsive background images, you must use CSS Media Queries with the image-set() or picture element equivalent in CSS (though less widely supported and more complex) or rely on the image-set() property for resolution switching (e.g., 1x, 2x for Retina screens).

.hero-banner { background-image: url('hero-default.jpg'); 
/* Default fallback */ 
@supports (background-image: -webkit-image-set(url('hero-1x.webp') 1x, url('hero-2x.webp') 2x)) 
 { 
   background-image: -webkit-image-set( url('hero-1x.webp') 1x, url('hero-2x.webp') 2x ); 
 } 
}

This is significantly more complicated than using the <picture> element and is a strong argument for prioritizing the use of HTML <img> for the LCP element whenever possible.

Advanced Techniques for Continuous Optimization

Achieving a high PageSpeed score is not a one-time fix; it is a continuous process. Implementing the following advanced techniques ensures your image delivery remains optimized for long-term performance.

Using an Image Content Delivery Network (CDN)

An Image CDN is a specialized service that not only delivers your images from geographically diverse servers but also performs real-time, on-the-fly optimization. When a user requests an image, the CDN checks their browser, device, and network speed, and then automatically serves the perfect image: the correct size, the optimal modern format (WebP or AVIF), and the best compression level. Services like Cloudinary, Imgix, or specialist image CDNs for WordPress abstract away all the complex manual steps involving srcset, sizes, and format conversion, making continuous optimization scalable and effortless. They are an essential tool for high-traffic or large e-commerce sites.

Image Placeholders and Low-Quality Image Placeholders (LQIP)

To enhance the perceived loading speed and user experience, implement an image placeholder while the high-resolution image is downloading. This can be a simple, solid color block that matches the image’s dominant color, or a more advanced technique known as Low-Quality Image Placeholder (LQIP). LQIP involves creating an extremely small, highly compressed version of the image (often just a few kilobytes) and inlining it using a data URI within the HTML. This blurry, low-res image is displayed instantly, giving the user an immediate sense of the content, which then smoothly transitions to the full-resolution image once it loads. This technique significantly improves the perceived performance even if the technical LCP time remains the same.

Vector Graphics for Logos and Icons

For logos, icons, and non-photographic graphics, always use Scalable Vector Graphics (SVG). SVGs are text-based, infinitely scalable without any loss of quality, and their file sizes are often minuscule. They also do not contribute to LCP, as they are not raster images, and are rendered directly by the browser’s engine. Replacing all instances of PNG logos or icons with optimized SVGs is a simple, high-impact win for performance and future-proofing your design assets.

All of these steps—from format and compression to strategic prioritization and responsive delivery—work synergistically. Implementing just one technique will help, but only a systematic approach covering all seven steps will reliably push your PageSpeed score into the green and ensure your Largest Contentful Paint is consistently below the 2.5-second benchmark.

Conclusion

The quest for a 90+ PageSpeed score and a sub-2.5 second Largest Contentful Paint is fundamentally an exercise in superior image management. By systematically replacing legacy image formats with modern ones like WebP and AVIF, you achieve the first and greatest reduction in file size. Next, employing the srcset and sizes attributes is crucial, ensuring every user, especially those on mobile, only downloads the image resolution appropriate for their screen, thereby minimizing the LCP resource load time.

This is then fortified by using fetchpriority=”high” or rel=”preload” to explicitly prioritize the LCP element for the browser. Finally, utilizing loading=”lazy” for all off-screen images and including explicit width and height attributes for layout stability completes the optimization stack. This comprehensive, technical framework is the definitive path to not only satisfying Core Web Vitals but also delivering a fast, efficient, and visually rich experience for all your website visitors, resulting in lower bounce rates and a stronger SEO profile.

Watch the Guide: Instant LCP Fix and Image Optimization Example

Leave a Reply

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