Image Optimization: WebP, AVIF, and Lazy Loading Made Simple
If your website feels slow, the culprit is very often sitting in plain sight: your images. A single uncompressed photo straight from a phone camera can weigh several megabytes, more than the rest of the page combined. Multiply that by a gallery or a product catalogue, add visitors on mobile networks where data is expensive, and you have a recipe for slow pages, frustrated visitors and lost sales.
The good news is that image optimization is one of the simplest and most effective speed fixes there is. This guide explains it in plain language: which formats to use (and what WebP and AVIF actually are), how to resize and compress, how lazy loading works and when not to use it, and how to put it all together on a WordPress site, step by step.
Key takeaways
Images are often the heaviest part of a web page, so they have the biggest effect on load time and on Core Web Vitals.
Use the right format: WebP or AVIF for photos, SVG for logos and icons, PNG only when you need sharp graphics or transparency.
Resize images to the size they are actually displayed before you upload them. Compression cannot fix an oversized image.
Lazy load images below the fold, but never the main image at the top of the page, which should load first.
Always set width and height on images, so the page does not jump around while it loads.
On WordPress, much of this is automatic, and plugins can handle the rest. Take a backup before optimizing your whole library.
Why Image Optimization Matters
Faster pages. Smaller images download sooner, especially on mobile connections, which improves Largest Contentful Paint (LCP), one of Google's Core Web Vitals.
Better user experience. Visitors leave slow pages. A fast-loading page feels professional and trustworthy.
Lower data use. Many of your visitors browse on mobile data. Lighter pages cost them less and load more reliably on weaker networks.
Better SEO. Google considers page experience, and faster sites tend to perform better in search and in image search.
Less storage and bandwidth. Optimized images save space on your hosting account, which matters on plans with defined storage limits.
Higher conversions. On online stores, product images need to be sharp and fast. Slow image loading hurts sales.
The Five Levers of Image Optimization
Right format: use modern formats such as WebP and AVIF where they suit the image.
Right size: match the pixel dimensions to where the image is displayed.
Right compression: reduce file size with the least visible loss of quality.
Right timing: load important images first and delay the rest (lazy loading).
Right delivery: serve responsive sizes, cache images well and use HTTPS and a good host or CDN.
Image Formats Compared
Format | Best for | Strengths | Limits |
|---|---|---|---|
JPEG | Photographs | Universal support, good compression | No transparency, quality drops with heavy compression |
PNG | Screenshots, graphics with sharp edges, transparency | Lossless, supports transparency | Large files for photos |
GIF | Simple animations | Universal support | Very large for animation, only 256 colours. Use short video instead |
SVG | Logos, icons, simple illustrations | Scales perfectly, tiny files, editable | Not suited to photos |
WebP | Photos and graphics, with or without transparency | Smaller than JPEG and PNG, supports transparency and animation | Slightly older software may not open it |
AVIF | Photos, especially where size matters most | Often the smallest files, high quality | Slower to create, newer, so keep a fallback |
Google's WebP documentation reports that lossy WebP images are typically 25% to 34% smaller than comparable JPEG images at equivalent quality. AVIF can often reduce sizes further, though results vary from image to image.
WebP vs AVIF: Which One Should You Use?
WebP is the safe, practical choice. It is supported by all current major browsers, creates much smaller files than JPEG, and is quick to produce.
AVIF often produces the smallest files at similar quality, and is supported by current versions of the major browsers. It takes longer to encode, so it suits sites with a good conversion tool or plugin.
The best approach is to offer AVIF first, WebP second and JPEG or PNG as a fallback, so every visitor gets the best format their browser can handle.
If you only want one, choose WebP.
Because older browsers may not support newer formats, always keep a fallback. The picture element and most optimization plugins handle that automatically.
Step 1: Audit Your Images
Start by finding out what you are dealing with.
Run your site through PageSpeed Insights or GTmetrix. Look at recommendations such as properly sizing images, serving images in next-generation formats, efficiently encoding images and deferring offscreen images.
Check which image is your Largest Contentful Paint element. That is the one that must load fast.
Open your browser's developer tools, go to the Network tab, filter by Img and sort by size. The biggest files are your first targets.
Note the total page weight before you begin, so you can measure the improvement.
Step 2: Resize Before You Upload
A 6000-pixel photo displayed in a 800-pixel column wastes bandwidth, however well it is compressed. Resize images to the largest size they will actually be displayed at.
Image type | Typical maximum width |
|---|---|
Full-width hero or banner | 1600 to 2000 px |
Image in a blog or content column | 800 to 1200 px |
Product images | 800 to 1200 px, with a larger version for zoom if needed |
Thumbnails and cards | 300 to 600 px |
Logos and icons | SVG, where possible |
These are rules of thumb, not strict limits. For sharp results on high-resolution screens, an image may be up to twice its display width, but rarely more.
A free tool such as Squoosh in your browser, or any image editor, can resize a picture in seconds. If you use ImageMagick on the command line:
magick input.jpg -resize 1600x -quality 80 output.jpgStep 3: Compress Your Images
There are two kinds of compression:
Lossy removes some detail the eye barely notices, giving much smaller files. It is ideal for photographs.
Lossless shrinks the file without any quality loss, but the savings are smaller. It suits graphics, logos and screenshots.
For JPEG and WebP photos, a quality setting somewhere around 70 to 85 is a common starting point. Compare the result to the original at normal viewing size, and lower the quality until you can just see a difference, then go one step back.
A practical target for most sites is a hero image of a few hundred kilobytes at most, content images of roughly 100 KB or less, and thumbnails of a few tens of kilobytes. Treat these as guidance, since the right size depends on the image and its role.
Step 4: Convert to WebP and AVIF
You have several ways to create next-generation formats.
In your browser: Squoosh lets you compare formats and quality settings side by side.
On the command line: Google's cwebp tool creates WebP, and avifenc creates AVIF:
cwebp -q 80 photo.jpg -o photo.webp
avifenc photo.jpg photo.avifIn WordPress: image optimization plugins can convert your existing library and new uploads automatically, and serve the right format to each browser. Popular examples include ShortPixel, Imagify, EWWW Image Optimizer, Smush and Optimole. The LiteSpeed Cache plugin also includes image optimization features, so if your server runs LiteSpeed, check what it offers.
With a CDN: many content delivery networks can convert and resize images on the fly.
Whichever you choose, keep your original files. You may want to regenerate images later with different settings.
Step 5: Serve Responsive Images
A phone does not need the same image as a desktop. Responsive images let the browser pick the best size from several options you provide, using the srcset and sizes attributes. WordPress generates several sizes of every uploaded image and adds these attributes for you, which is one of the reasons to upload an image that is large enough but not oversized.
If you are building pages by hand, the picture element lets you offer several formats with a fallback, as well as multiple sizes:
<picture>
<source type="image/avif"
srcset="hero-800.avif 800w, hero-1600.avif 1600w"
sizes="(max-width: 800px) 100vw, 800px">
<source type="image/webp"
srcset="hero-800.webp 800w, hero-1600.webp 1600w"
sizes="(max-width: 800px) 100vw, 800px">
<img src="hero-800.jpg"
srcset="hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="(max-width: 800px) 100vw, 800px"
width="800" height="450"
alt="Describe the image here"
fetchpriority="high" decoding="async">
</picture>The browser picks the first format it supports, and falls back to the plain img tag if it supports none. This example is for a main image at the top of the page, so it has no lazy loading and has a high fetch priority.
Step 6: Lazy Load the Right Images
Lazy loading means the browser delays loading an image until the visitor is about to scroll to it. Pages with many images, such as long articles, galleries and product listings, load much faster because they only fetch what is needed.
Modern browsers support lazy loading natively with a single attribute:
<img src="product.webp" width="600" height="600" alt="Blue ceramic mug" loading="lazy" decoding="async">The golden rules of lazy loading
Never lazy load the main image at the top of the page. The hero image or the first large image is usually your Largest Contentful Paint element, and delaying it makes the page feel slower. Load it immediately and consider fetchpriority="high".
Lazy load images below the fold, such as the rest of the gallery, product grids and blog images further down.
Always give lazy-loaded images a width and height, so the browser can reserve space and avoid layout jumps.
Remember other elements. The same loading attribute works on iframes, such as embedded maps and videos.
Be careful with CSS background images. The loading attribute only applies to img and iframe elements. Background images need a different technique.
Avoid JavaScript-based lazy loading where native lazy loading will do, because it adds code and can hide images from search engines if done badly.
WordPress already adds loading="lazy" to images by default, and recent versions are careful to skip the first image on the page and can add a high fetch priority to the likely main image. Check your theme or page builder to make sure it is not overriding this.
Step 7: Prevent Layout Shift
If the browser does not know how big an image is, the page jumps when the image appears. That hurts Cumulative Layout Shift (CLS), another Core Web Vital, and annoys visitors who are about to tap something. Always include width and height attributes (or reserve space with CSS aspect ratio). WordPress does this for images added in the editor.
Step 8: Cache and Deliver Efficiently
Cache images for a long time. Images rarely change, so browsers should keep them. Using file names that change when the image changes lets you set a very long cache lifetime safely.
Use HTTPS. Browsers use the faster HTTP/2 and HTTP/3 protocols only over HTTPS, which helps when a page loads many images. SteboHost includes free SSL on every domain.
Use a fast server. NVMe storage and a server such as LiteSpeed deliver files quickly.
Consider a CDN if your visitors are far from your server.
Use video instead of animated GIFs. Short MP4 or WebM clips are far smaller.
Optimizing Images in WordPress
WordPress does a lot for you, and plugins can do the rest.
What WordPress does automatically
Creates several sizes of every uploaded image and adds responsive srcset and sizes attributes
Adds native lazy loading, while treating the first image on the page differently
Accepts WebP uploads, and AVIF uploads in recent versions
Adds width and height attributes to images inserted in the editor
What you should do
Resize before you upload, following the table in Step 2.
Install one image optimization plugin, not several, and configure it for WebP, AVIF where supported and a sensible compression level.
Back up first. Before bulk-optimizing your existing library, take a backup. SteboHost's daily backups with one-click restore give you a safety net.
Optimize the existing library in batches, starting with the biggest files, and check a sample of pages afterwards.
Regenerate thumbnails if you change your theme or image sizes, so old images match the new layout.
Use descriptive file names and alt text (see the next section).
Test on a copy of your site first if you are changing a lot. Managed WordPress hosting includes one-click staging sites.
Clear your caches after changes, and test again.
If you use a page builder or a theme with its own image settings, check that they are not undoing your work, for example by disabling lazy loading or loading oversized images in sliders.
Image SEO Basics
Optimized images also help people find you in Google Images and in regular search.
Descriptive file names: blue-ceramic-mug.webp beats IMG_4821.webp.
Alt text: describe what the image shows, in plain language, for people who use screen readers and for search engines. Do not stuff it with keywords.
Real text in HTML, not text baked into the image, so it can be read, translated and indexed.
Relevant context: place images near related text, with a caption where it helps.
Unique images where you can. Original photos of your products, work and team build trust.
Make sure images are crawlable: do not hide them behind scripts or login walls if you want them indexed.
A Privacy Tip: Strip the Metadata
Photos from phones and cameras often contain hidden EXIF data, which can include the date, device and even GPS location. Removing metadata makes files slightly smaller and avoids publishing details you did not intend to share, for example the exact location of a home or workshop. Most optimization tools and plugins have a "strip metadata" option.
Common Mistakes to Avoid
Uploading full-size photos straight from a phone or camera
Lazy loading the hero image, which slows down Largest Contentful Paint
Compressing too hard so images look blurry or blocky
Using PNG for photographs
Using animated GIFs instead of short video
Forgetting width and height, which causes layout shift
Installing several optimization plugins that fight each other
Deleting the original files before you are sure about the results
Skipping alt text
Optimizing without measuring before and after
Your Image Optimization Checklist
Audit with PageSpeed Insights and the Network tab
Resize images to their display size
Choose the right format: AVIF or WebP for photos, SVG for logos, PNG for sharp graphics
Compress with a quality you have checked by eye
Keep fallbacks for older browsers
Use responsive images with srcset and sizes
Lazy load below-the-fold images, but not the main image
Set width and height on every image
Add descriptive file names and alt text
Strip metadata
Back up before bulk changes, and clear caches afterwards
Re-test and compare page weight and LCP
How to Measure the Results
Compare total page weight and number of requests before and after in the Network tab.
Run PageSpeed Insights again and look at LCP and CLS.
Test both desktop and mobile, and use a throttled connection to see what slower networks experience.
Test several important pages, not just the homepage.
Keep an eye on speed over time. Monitoring helps you spot regressions when new images are added.
Why SteboHost Is a Great Home for a Fast, Image-Rich Site
Optimization starts with your images, but the server matters too. With SteboHost you get:
LiteSpeed web servers and NVMe storage, built for fast delivery of pages and images.
Managed WordPress with LiteSpeed caching, automatic core and plugin updates, one-click staging sites and free migration from any host.
Free SSL on every domain, so your visitors get HTTPS and the faster protocols that go with it.
Daily backups with 7-day retention and one-click restore, so you can bulk-optimize with confidence.
Clear storage limits on every plan, published on each plan page. Optimized images stretch that space much further. Check the plan limits for your plan.
WAF and Imunify360 malware scanning on every plan, with 24/7 infrastructure monitoring and a 99.9% uptime SLA.
Room to grow: move to VPS and cloud hosting if a large media library needs dedicated resources.
Local support on +254 703 610 464 and billing in KES by M-Pesa, card or bank transfer.
Current plan and renewal prices are shown before you buy. Compare plans and pricing, explore SteboHost web hosting, or browse the knowledge base for more performance guides.
Conclusion
Image optimization is the rare speed improvement that is simple, cheap and very effective. Resize before you upload, compress sensibly, use WebP and AVIF with fallbacks, lazy load what is below the fold, keep the main image fast and always set dimensions. Combine that with fast hosting and good caching, measure your results, and your pages will feel faster to every visitor, wherever they are and whatever connection they are on.
Want a faster website? Explore SteboHost web hosting, or contact the team or call +254 703 610 464, and SteboHost will help you choose the right plan for an image-rich site.
Frequently Asked Questions
Is WebP better than JPEG?
For most web uses, yes. WebP files are typically noticeably smaller than JPEG files at similar visual quality, and WebP also supports transparency, which JPEG does not. All current major browsers support it. Keep a JPEG fallback if you need to support very old browsers or software.
What is the difference between WebP and AVIF?
Both are modern formats that produce smaller files than JPEG. AVIF often gives the smallest files at similar quality, but it takes longer to create and is newer, while WebP is faster to produce and has been supported everywhere for longer. The best practice is to offer AVIF first, WebP second and a JPEG or PNG fallback.
Does lazy loading hurt SEO?
Not when it is done properly. Native lazy loading with the loading attribute is supported by modern browsers and works well with search engines. The risks come from lazy loading the main image at the top of the page, which can slow down the Largest Contentful Paint, or from using scripts that hide images from crawlers.
Should I lazy load every image?
No. Load the main image at the top of the page immediately, and lazy load the images that are further down. Lazy loading an image that is visible when the page opens delays it and makes your page feel slower.
What size should website images be?
It depends on where they appear. As a rule of thumb, full-width hero images are about 1600 to 2000 pixels wide, images in a content column are 800 to 1200 pixels, and thumbnails are 300 to 600 pixels. Aim for small file sizes, such as a few hundred kilobytes at most for a hero image and around 100 KB or less for content images.
Do I need a plugin to optimize images in WordPress?
Not strictly, because WordPress already creates responsive sizes and adds lazy loading. But a plugin is the easiest way to convert images to WebP or AVIF, compress your existing library and strip metadata. Choose one reputable plugin, and back up your site before bulk-optimizing.
Will compressing or converting images reduce their quality?
Lossless compression keeps quality exactly the same. Lossy compression and format conversion remove some detail, but at sensible settings the difference is hard to see, while the file size drops sharply. Compare results by eye, keep your original files, and adjust the quality setting if you notice any problems.
Written by Mercy Chepkemoi
SteboHost engineering and operations team. We write practical guides on hosting, domains, email and security for African businesses — based on what we see in the field, not marketing copy.
Ready to get started?
Browse our hosting plans or contact our team for help choosing the right one.