Speed & performance · Guide
How to Optimize Images for WordPress
Short answer
Optimize images for WordPress by exporting each file at the size it will display, compressing photos as WebP or AVIF, and letting WordPress serve the right size through srcset. Keep lazy loading for below-the-fold images only, and never lazy-load the hero image.
Key takeaways
- Desktop-sized images served to phones can use 2 to 4 times more data than needed.
- WordPress creates thumbnail, medium, medium large and large copies of every upload.
- Lossy WebP is 25 to 34 percent smaller than JPEG at the same quality.
- WordPress 5.5 lazy-loads images by default; 5.9 skips the first one.
- Never lazy-load the hero image, which is usually the LCP element.
Why do images slow down WordPress?
Images slow down WordPress because they are usually the heaviest files on a page, and oversized images waste data on every visit.
A photo uploaded straight from a camera can be several megabytes. When that file is shown at a fraction of its size, the browser still downloads the whole thing.
Serving a desktop-sized image to a phone is the worst case. Web.dev notes that serving desktop-sized images to mobile devices can use 2 to 4 times more data than needed.
Images also hurt the page's Largest Contentful Paint, which is often a hero image. Web.dev explains that serving a large image responsively can reduce its load time, which improves the LCP score.
The fix has four parts: pick the right format, compress the file, serve the right size, and load below-the-fold images later. Each part is simple on its own, and together they cut image weight by a large amount.
What image sizes does WordPress create by default?
WordPress creates several smaller copies of every image you upload, so the browser can pick the size that fits.
The default sizes are thumbnail at 150 by 150 pixels, medium at 300 by 300 pixels, medium large at 768 pixels wide, and large at 1024 by 1024 pixels, plus the full-size original.
Developer.WordPress.org lists these exact values in its wp media image-size reference, with thumbnail cropped hard to a square and the rest scaled softly.
You can change the thumbnail, medium and large sizes under Settings, then Media. The medium large size is fixed at 768 pixels wide and does not appear on that settings screen.
Themes and plugins can add their own sizes on top of these. A theme may register a wide banner size or a small card size, and each upload then creates even more files.
Which format should you use for each image?
Use the format that gives the smallest file at the quality you need, with a fallback for older browsers.
| Format | Best for | File size | Notes |
|---|---|---|---|
| AVIF | Large photos and hero images | Smallest | Best compression, slower to encode |
| WebP | Photos, screenshots, graphics | Smaller than JPEG and PNG | Safe default, lossy and lossless modes |
| JPEG | Photos on older setups | Baseline | No transparency, universal support |
| PNG | Logos, screenshots, crisp graphics | Largest for photos | Lossless, supports transparency |
| SVG | Icons, logos, diagrams | Tiny | Vector, scales without losing sharpness |
WebP is the safe default for most sites. Google for Developers reports that lossy WebP images are 25 to 34 percent smaller than comparable JPEG images at the same quality, and lossless WebP images are 26 percent smaller than PNG images.
AVIF goes further on photographs, but it takes longer to encode and not every tool supports it yet. Use it for hero images where every kilobyte matters, and keep WebP as the fallback.
Never use PNG for photographs. PNG is lossless, so a photo saved as PNG can be several times larger than the same photo as JPEG or WebP.
Use SVG for icons and logos, not for photos. An SVG is text, so it stays tiny and sharp at any size, while a PNG logo at retina size is far heavier.
Our guide to serve images in next-gen formats in WordPress walks through the conversion step by step.
For context on adoption, our image format usage statistics show which formats sites actually use.
How do you compress images before uploading?
Compress every image before it reaches WordPress, because the upload is the last chance to control its size.
Start with the right pixel size. Resize the image to the largest size it will ever display, such as 1200 pixels wide for a full-width image, and never upload a 4000-pixel camera file for a 600-pixel slot.
Export photos as JPEG or WebP at a quality setting of 75 to 85. Most photos look the same at 80 as they do at 100, and the file is far smaller.
Export graphics with flat colours or text as PNG or WebP lossless. A screenshot saved as JPEG shows smudges around text, while the same shot as PNG stays crisp.
Use a browser-based compressor when you have only a few images. A side-by-side preview shows the original next to the compressed version, so you can compare quality before you save.
Strip metadata from the file when the tool offers it. Camera data, location tags and editing history add weight and can leak details you did not mean to publish.
How do you serve the right size to each device?
Serve the right size by giving the browser several versions of the same image and letting it pick the best one.
WordPress does most of this for you. When it creates the thumbnail, medium, medium large and large copies, it also writes srcset and sizes attributes into the image tag, so the browser can choose.
The srcset attribute lists each version with its width, such as 480w and 1080w. The sizes attribute tells the browser how wide the image will display, so it can pick the version that fits.
Web.dev states that it is common to serve 3 to 5 different sizes of an image, because more sizes give the browser a better match, at the cost of more storage.
Check that your theme actually uses the responsive markup. Open a post, inspect an image, and look for srcset in the tag. A theme that hard-codes a single large file defeats the whole system.
Fix oversized images that Lighthouse flags. Web.dev recommends running the Lighthouse performance audit and reading the Properly size images results, which list the images you still need to resize.
Our guide to properly size images in WordPress covers the exact settings for common layouts, including full-width images and sidebars.
How do you lazy-load images the right way?
Lazy loading delays images below the fold until the visitor scrolls near them, so the first screen loads faster.
WordPress adds lazy loading by default. Make WordPress Core states that WordPress 5.5 adds loading="lazy" to all img tags that have width and height attributes, using the native HTML loading attribute.
The width and height attributes matter as much as the lazy load itself. With both present, the browser reserves the right amount of space before the image arrives, so the page does not jump when it loads.
Do not lazy-load the hero image. WordPress 5.9 skips the first content image or iframe from lazy loading, because that image is usually in the first screen. Make WordPress Core reports that an analysis of 50 popular themes showed LCP improvements of up to 30 percent from this change.
Check for double lazy loading. A cache plugin or a theme can add its own lazy load on top of the native one, and the two systems can fight, delaying images that should load at once.
If a plugin offers lazy loading, compare it with the native behaviour first. Native lazy loading needs no JavaScript, while a plugin version swaps image sources with JavaScript and can fail when scripts are delayed.
How do you fix the hero image so it loads first?
The hero image deserves special treatment, because it is usually the Largest Contentful Paint element.
Give the hero the largest useful size, not the largest file you have. A 1600-pixel wide AVIF or WebP at quality 75 is enough for most full-width heroes, and it loads far faster than a 4000-pixel original.
Set fetchpriority="high" on the hero image tag. That tells the browser to start it before other images, and it pairs with the WordPress 5.9 rule that keeps the first image out of lazy loading.
Do not lazy-load the hero under any setting. Open the page source, find the hero img tag, and confirm it has no loading="lazy" attribute.
Preload the hero when the theme allows it. A preload hint in the page head tells the browser to fetch the file early, before it discovers the image in the markup.
Test the change with PageSpeed Insights and read the LCP value. A faster hero shows up directly in that number, and our guide to pass Core Web Vitals in WordPress explains the thresholds in full.
How do you bulk-optimize the images you already have?
Bulk optimization fixes the library you already built, without re-uploading every file by hand.
Install an image optimization plugin and run its bulk action from the media library. The plugin compresses each file and, when set, converts it to WebP or AVIF.
WP-Optimize is one free option that covers both jobs. WordPress.org states that it cleans post revisions, auto drafts, trashed posts, spam and trashed comments, and that clean-ups can run on a daily, weekly, fortnightly or monthly schedule.
LiteSpeed Cache also bundles image optimization. WordPress.org lists image optimization with lossless and lossy modes among its general features, which work on any web server.
Run the bulk job in small batches, such as 50 images at a time. A large library can time out on shared hosting, and a failed batch can leave half the library converted.
Back up the media folder before a bulk run. Some plugins replace the original file, and a backup is the only way back when a conversion looks wrong.
After the run, spot-check ten images across the site. Open posts, product pages and galleries, and confirm the images still look right and load from the new format.
What mistakes waste the most image bytes?
Uploading camera-size originals is the biggest mistake, because no later step can recover the wasted bytes.
Using PNG for photographs is the second mistake. A photo saved as PNG can be several times larger than the same photo as WebP, with no visible gain.
Lazy-loading the hero is the third mistake. It delays the very image that decides the LCP score, and it undoes the WordPress 5.9 fix that skips the first image.
Skipping width and height is the fourth mistake. Without them the browser cannot reserve space, so content jumps as images arrive, and the layout shift hurts both readers and scores.
Forgetting old images is the fifth mistake. Deleted posts often leave their uploads behind, so open Media, then Library, and remove files no post uses, or use a plugin that finds unattached media.
If an image disappears after optimization, check the file name first. Our guide to fix images not showing covers the common causes, from wrong paths to plugin conflicts, before you re-upload anything.
Frequently asked questions
Should I use WebP or AVIF?
WebP is the safe default for photos, screenshots and graphics. AVIF makes smaller files still, but it encodes more slowly and fewer tools support it. Use AVIF for hero images and WebP everywhere else, with a JPEG fallback for old browsers.
Does WordPress convert my old images to WebP by itself?
No. WordPress accepts WebP uploads but does not convert your existing library on its own. Use an image optimization plugin to bulk-convert the media library, then check that the new files are actually served.
Why is my hero image lazy-loaded?
WordPress 5.5 adds loading=lazy to images that have width and height attributes. WordPress 5.9 skips the first content image, because it is usually the hero. Check the page source if a hero still carries the lazy attribute.
How do I fix one image that is too large?
Resize it to the largest size it will display, export it at quality 75 to 85, and convert it to WebP or AVIF. A camera original at 4000 pixels wide is the most common cause of a slow image, and no plugin can fix the wasted bytes.
Is PNG a good format for photographs?
No. PNG is lossless, so a photograph saved as PNG can be several times larger than the same photo as WebP. Keep PNG for logos, screenshots and graphics with sharp edges or transparency, and use WebP or JPEG for photos.
How do I know responsive images are working?
Open a post, inspect an image and look for srcset in the tag. If the tag lists several widths, the browser can pick the best fit. If it shows one large file, the theme may be hard-coding a single size.
Sources
- Serve responsive images web.dev
- An image format for the Web (WebP) Google for Developers
- wp media image-size Developer.WordPress.org
- Lazy-loading images in 5.5 Make WordPress Core
- Enhanced lazy-loading performance in 5.9 Make WordPress Core
- WP-Optimize WordPress.org
- LiteSpeed Cache WordPress.org
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
