Cheat sheet #8

Raster image formats for the web

A cheat sheet for web design students. Learn what a raster image is and why file size matters, and find out how WebP, AVIF, JPEG, PNG and GIF each strike a balance between image quality and download weight.

The short version

Always aim for the smallest file that still looks good. For most websites, that means:

Photos AVIF or WebP, with a JPEG fallback Transparency WebP, with a PNG fallback Animation video or WebP, rather than GIF
On this cheat sheet

What is a raster image?

A grid of coloured squares

A raster image (also called a bitmap) is a picture stored as a grid of tiny squares called pixels, arranged in rows. Each pixel holds exactly one colour, and together they form the picture. The word comes from the way old television screens drew an image line by line, in what was known as a “raster scan”.

An 8 × 6 raster image: 48 pixels. If you zoomed in far enough on any photograph, you’d see the same thing, a mosaic of single-colour squares. A real photo simply has millions of them.

TermMeaningWhy it matters for the web
Pixel dimensionsThe width and height in pixels, such as 1200 × 800More pixels means more data. Never send a 4000-pixel-wide image to fill a 400-pixel space.
Colour depthHow many colours each pixel can have: 256 colours (8-bit palette), millions (24-bit) or more (HDR)More colours means a larger file, but smoother gradients
Lossy compressionShrinks the file by permanently discarding detail the eye is unlikely to noticeMuch smaller files, but quality drops as compression increases
Lossless compressionShrinks the file with no loss of information: you get back exactly what you put inPerfect quality, but a larger file
Alpha transparencyA per-pixel see-through value, so the page shows throughNeeded for logos and cut-outs on varied backgrounds
AnimationSeveral frames stored in one fileEach extra frame adds to the file size
Raster is best for
  • Photographs
  • Images with rich, continuous colour and texture
  • Screenshots
Raster’s limitations
  • It has a fixed resolution, so if you enlarge it beyond its pixel dimensions, it turns blurry or blocky.
  • The file size grows with the pixel count and the amount of detail.
  • For logos, icons and line art, a vector SVG is usually a better choice (see cheat sheet 7).

The key objective: size versus quality

Find the best possible balance

When we work with web images, our goal is to find the best balance between file size and image quality. A bigger file looks better, but it takes longer to load. A smaller file loads quickly, but if it’s compressed too much, it looks poor. The best choice is the smallest file that still looks good at the size it’s displayed.

Why the balance matters:

There are three levers you control. The first is the file format (covered in the rest of this cheat sheet). The second is the pixel dimensions, also known as the intrinsic dimensions (resize the image to its displayed size). The third is the compression level (the quality slider when you export). In addition, you can improve user experience by controlling delivery, with lazy loading and responsive image sizes. Each of the formats below is judged by how well it strikes the balance.

The formats at a glance

FormatCompressionTransparencyAnimationFile size (photos)Browser support
WebPLossy and losslessYes, smoothYesSmallAbout 97%
AVIFLossy and losslessYes, smoothYesSmallestAbout 95%
JPEGLossy onlyNoNoMediumUniversal
PNGLossless onlyYes, smoothNo (not normally)LargeUniversal
GIFLossless, 256 coloursOn or off onlyYesPoor for photosUniversal

How common is each format today?

This chart shows the percentage of websites that use each format, according to W3Techs on 26 October 2026. Because a site can use several formats, the figures add up to more than 100%. SVG is shown for reference.

The trend matters as much as the figures. Back in 2014, GIF was used by about half of all websites, and WebP was essentially unused. Since then, WebP has grown steadily to just under a quarter, and AVIF is small but rising. The browser support figures in this cheat sheet are approximate global figures from caniuse.com. Check both sources for the current numbers.

WebP

The modern all-rounder

CreatedGoogle, 2010
Browser supportAbout 97% globally. All current Chrome, Firefox, Safari (14+) and Edge.
Used by23.1% of websites
File extension.webp

Features

Pros
  • It gives great size savings over JPEG and PNG.
  • One format covers photos, transparency and animation.
  • It has near-universal browser support.
  • It’s quick to create, so it’s easy to add to a workflow.
Cons
  • It only supports 8-bit colour, so there’s no HDR or wide-range colour.
  • The savings are smaller than AVIF’s.
  • Some software doesn’t support it, including certain design and print tools and some email clients.
  • A very small share of old browsers still can’t display it.

Example use case: the default format for a general website, for product photos, blog images, and cut-out graphics with a transparent background that would otherwise be heavy PNGs.

AVIF

The most efficient compression

CreatedAlliance for Open Media, 2019
Browser supportAbout 95% globally. Chrome 85+, Firefox 93+, Safari 16.4+, Edge 121+.
Used by1.7% of websites (small, but rising)
File extension.avif

Features

Pros
  • It gives the best balance of small size and good quality.
  • It offers rich colour, with HDR and wide gamut.
  • It makes big savings on image-heavy pages, which means faster loading and less energy used.
Cons
  • It’s slow and processor-hungry to encode, which suits automated build tools better than quick manual exports.
  • It can be slower to decode on low-end devices.
  • Heavy compression can smooth away fine texture, so photos can look slightly “plastic”.
  • Browser support is slightly lower than for WebP, and tool support is patchier, so always provide a fallback.

Example use case: large hero photographs and image galleries on performance-sensitive sites, served with a WebP or JPEG fallback. The bigger the images, the more AVIF will save.

JPEG

The long-standing standard for photographs

CreatedJoint Photographic Experts Group, 1992
Browser supportUniversal. Every browser and device.
Used by68.8% of websites
File extension.jpg (or .jpeg)

Features

Pros
  • It works absolutely everywhere, including in email and old software.
  • It’s fast and well understood, and every tool supports it.
  • It gives good quality for photographs at modest file sizes.
Cons
  • It’s less efficient than WebP and AVIF, so files are larger for the same quality.
  • It has no transparency.
  • Heavy compression causes blocky artefacts, and it looks poor on sharp edges, text and flat-colour graphics.
  • Every re-save loses a little more quality, so always keep your original.

Example use case: the universal fallback for photographs. It’s the last choice inside a <picture> element, which ensures that every browser gets an image.

PNG

Lossless images with transparency

CreatedPNG Development Group, 1996
Browser supportUniversal. Every browser and device.
Used by74.9% of websites, the most used format
File extension.png

Features

Pros
  • It gives perfect quality, so it’s ideal for graphics, text and screenshots.
  • Its transparency is reliable.
  • It has universal support and tooling.
  • It’s excellent as a master copy for editing.
Cons
  • Files are very large for photographs. A photo saved as a PNG can be many times the size of the same photo saved as a JPEG.
  • It’s larger than WebP or AVIF for the same graphic.
  • There’s no lossy option, so you can’t trade a little quality for a much smaller file.

Example use case: a screenshot or a diagram with text that must stay sharp, or a logo with transparency when an SVG isn’t suitable. For flat graphics, check whether a palette PNG or a lossless WebP gives you a smaller file.

GIF

The legacy animation format

CreatedCompuServe, 1987
Browser supportUniversal. Every browser and device.
Used by13.2% of websites, down from about half in 2014
File extension.gif

Features

Pros
  • It works everywhere, including in email.
  • It’s simple, and it plays automatically with no controls needed.
  • It’s fine for tiny, simple animations.
Cons
  • It’s very inefficient. Animated GIFs are often many times larger than the same clip as a video, WebP or AVIF.
  • It’s limited to 256 colours, so photos look banded and speckled.
  • It has no smooth transparency.
  • It’s hard to pause, and moving content can be a problem for people with motion sensitivity or attention difficulties.

Example use case: a small, simple animation, such as a tiny loading indicator, where universal support matters (in an email, for example). For anything longer or more detailed, use a video (MP4 or WebM) or an animated WebP.

Choosing a format

Your image is…First choiceFallback
A photographAVIF or WebP (lossy)JPEG
A cut-out or graphic with soft transparencyWebP or AVIFPNG
A screenshot, or a diagram with textPNG or lossless WebPPNG
A logo, icon or line illustrationSVG (see cheat sheet 7)PNG
A short animationVideo, or animated WebPGIF as a last resort

Serve the best format the browser can show

The <picture> element lists the same image in several formats, from smallest to largest, and the browser uses the first one it supports. The <img> at the end is the universal fallback. (Note that source and img are both void elements, as described in cheat sheet 3.)

<picture> <source srcset="images/hero-mountains.avif" type="image/avif"> <source srcset="images/hero-mountains.webp" type="image/webp"> <img src="images/hero-mountains.jpg" alt="Snow-capped peaks at dawn" width="1200" height="800" loading="lazy"> </picture>

Getting the balance right

Do thisWhy
Resize first. Export at the size it is displayed, or at twice that for sharp high-density screens.Pixel count is the biggest driver of file size
Choose the right format for the content (table above)The same image can differ many times in size between formats
Use the quality slider. Lower it until you can just see a difference, then step back up.Finds the sweet spot for each image
Keep an uncompressed original and export copies from itAvoids losing quality through repeated re-saving
Strip unneeded metadata such as camera and location dataSaves bytes and protects privacy
Lazy-load images below the foldVisitors never download images they don’t scroll to

Free tools such as Squoosh let you compare formats and quality settings side by side, and they show you the resulting file size, so you can judge the balance by eye.

Common mistakes

MistakeFix
Saving a photograph as PNGUse AVIF, WebP or JPEG
Using JPEG for logos, text or flat graphicsUse SVG, PNG or lossless WebP, to avoid blocky artefacts
Uploading a 4000-pixel camera photo and shrinking it with CSSResize the file itself to the displayed size
Using an animated GIF for a long clipUse video, or animated WebP
Converting a JPEG to PNG to “improve” itIt can’t restore lost detail and only makes the file bigger
Re-saving a JPEG again and againExport from the original every time
AVIF or WebP with no fallbackUse <picture> with a JPEG or PNG img
Lazy-loading the top-of-page imageLoad it normally so it appears quickly
Missing alt, width or heightAdd all three, so the page is accessible and doesn’t jump as it loads

Check before you upload

Learn more

Sources: usage figures are from W3Techs (26 October 2026), and the browser support figures are approximate global shares from caniuse.com. Both change over time, so check them for the latest numbers.