Digital content
Optimise Images for Web and Blog: Formats, Size and Alt Text
Optimising an image means choosing a suitable format, resizing it to the size it is actually displayed at, compressing it to a quality that still looks right, and describing it with alt text. Reserve its space with width and height attributes and lazy load only images that sit below the first screen.
By CodingMarble · Published · 4 min read

Pick the right format for the job
Image formats are different ways to store the same picture, each with its own trade-offs between file size, quality and features. There is no single best format, so choose by what the image contains.
- JPEG suits photographs and images with smooth colour gradients. It uses lossy compression, which discards detail to save space, and it does not support transparency.
- PNG suits screenshots, logos with sharp edges, and anything that needs transparency. It is lossless, so file sizes for photographs can be large.
- WebP is a modern format that supports both lossy and lossless compression and transparency. Browser support is broad today, but check current compatibility tables for your audience.
- AVIF is a newer format that can reach small file sizes for photographs. Support and encoding speed vary by browser and tool, so confirm before relying on it, and provide a fallback.
- SVG is a vector format described by shapes rather than pixels. It stays sharp at any size and suits icons, simple logos and diagrams. It is a poor choice for photographs.
A common approach is to serve modern formats with a JPEG or PNG fallback using the picture element, so that older browsers still show something.
Match dimensions to display size
The most frequent mistake is uploading a camera original. A phone photo may be several thousand pixels wide, but a blog column might show it at 700 pixels across. The browser downloads every pixel and then throws most of them away. Resize the image to roughly the largest width it will be shown at. Because many screens pack extra pixels into the same physical space, a version around twice the displayed width is often enough for sharp results, and more than that is rarely visible.
To find the right width, open your page in the browser's developer tools, inspect the image and read its rendered size. Compare it with the file's real dimensions, which tools show on the same panel. A large mismatch is wasted bandwidth that your visitors, especially those on mobile data, pay for.
Compress with your eyes, not a magic number
Lossy formats use a quality setting that trades size against visible damage. There is no universal correct value, because the result depends on the picture. A photo with soft detail survives heavy compression, while an image with fine text or sharp edges shows blocky artefacts sooner. Export a version, view it at the size readers will see it, and lower the quality until you first notice a flaw, then step back a little.
Keep your originals untouched in a separate folder and export web copies from them. Re-compressing an already compressed JPEG compounds the damage. If you need to process many files, use a bulk tool. CodingMarble runs a free browser-based image tool at loveimage.codingmarble.com that can compress, resize, crop and convert images, including in bulk.
Responsive images with srcset and sizes
A single file cannot be ideal for both a small phone and a wide desktop. The srcset attribute lists several versions of an image with their real widths, and sizes tells the browser how wide the image will be displayed at different viewport widths. The browser then picks the smallest suitable file. Here, w descriptors give the file widths, and the sizes value says the image fills the screen on small viewports and fills 700 pixels on larger ones.
<img
src="harbour-800.jpg"
srcset="harbour-400.jpg 400w,
harbour-800.jpg 800w,
harbour-1400.jpg 1400w"
sizes="(max-width: 760px) 100vw, 700px"
width="1400"
height="933"
alt="Fishing boats tied up along a stone harbour wall at low tide"
loading="lazy"
decoding="async">The src attribute is the fallback for browsers that ignore srcset. The width and height attributes carry the file's intrinsic dimensions, not the displayed size. If you want to switch formats, wrap several source elements inside a picture element, each with its own type, and keep an img as the last child.
Lazy loading and layout shift
Adding loading="lazy" asks the browser to postpone fetching an image until the reader is near it. This saves data for images further down the page that many visitors never reach. Do not use it on the image at the top of the page, such as a hero or the main post image, because it is the first thing the visitor sees and delaying it makes the page feel slower. Test by scrolling a long page with the network panel open and confirm that images below the fold load as you approach them.
Layout shift happens when an image arrives and pushes the text around, because the browser did not know its size. Setting width and height attributes lets the browser reserve the correct space from the aspect ratio before the file loads. With a style such as max-width: 100% and height: auto, the image still scales fluidly. To understand how this affects measured page experience, see the guide on Core Web Vitals.
Alt text and file names
Alt text is a short description in the alt attribute. It is read by screen readers, shown when an image fails to load and used by search engines to understand the picture. Describe what the image contributes in context: a chart of monthly visitors needs its main finding, while a decorative divider needs an empty alt attribute so assistive tools skip it. Do not start with the phrase image of, and do not stuff keywords into it.
File names should be lowercase, use hyphens between words and say what the picture shows, such as stone-harbour-fishing-boats.jpg rather than IMG_4821.jpg. This helps you find files later and gives search engines a small hint.
Practical tip: before publishing, open the page on a phone with mobile data and a throttled connection setting from your browser's developer tools. If any single image takes noticeably long, resize or recompress it, and check that no image is much larger than the box it appears in.
Keep reading
- Everyday digital lifeCompress PDF and Images for Email Without Losing QualityFiles are large mainly because of high-resolution images, and you can shrink them by lowering image dimensions, choosing a suitable format and quality, and exporting PDFs with reduced image resolution. When a file is still too big for email, share a link instead, and be careful about which online tools you upload private documents to.
- Web developmentCore Web Vitals Explained: LCP, INP and CLSCore Web Vitals are three measurements of real user experience: how fast the main content appears (LCP), how quickly the page responds to input (INP) and how much the layout jumps (CLS). Each has a published threshold, a short list of usual causes and a specific fix.
- Digital contentAccessibility for Content Writers: Alt Text and MoreAccessible content is content that people can read, hear, navigate and understand whatever their eyes, ears, devices or situation. As a writer you control a lot of it: alt text that describes purpose, headings in order, links that make sense alone, plain language, and captions or transcripts for media.
- Web developmentHow to Speed Up a Next.js WebsiteMost slow Next.js sites are slow for ordinary reasons: oversized images, late-loading fonts, too much client-side JavaScript and uncached data. Fix those four in order, and measure with both Lighthouse and real-user data so you know the change helped.
Need this built properly for your business?
CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.