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 GIFOn 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.
Term
Meaning
Why it matters for the web
Pixel dimensions
The width and height in pixels, such as 1200 × 800
More pixels means more data. Never send a 4000-pixel-wide image to fill a 400-pixel space.
Colour depth
How 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 compression
Shrinks the file by permanently discarding detail the eye is unlikely to notice
Much smaller files, but quality drops as compression increases
Lossless compression
Shrinks the file with no loss of information: you get back exactly what you put in
Perfect quality, but a larger file
Alpha transparency
A per-pixel see-through value, so the page shows through
Needed for logos and cut-outs on varied backgrounds
Animation
Several frames stored in one file
Each 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.
Smallest file Lowest quality
The sweet spot
Largest file Highest quality
Why the balance matters:
User experience. Images are often the largest part of a page’s download. Smaller image files mean that pages appear faster, which helps to keep visitors, and they provide a smoother experience on slow connections and limited mobile data allowances.
Sustainability. Every byte sent across the internet uses energy in data centres, networks and devices. Sending less data lowers a website’s environmental footprint, and the saving is multiplied by every visitor.
Quality still counts. Over-compressed images look careless and can lose important detail, so the aim is efficiency, not the smallest possible file.
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
Format
Compression
Transparency
Animation
File size (photos)
Browser support
WebP
Lossy and lossless
Yes, smooth
Yes
Small
About 97%
AVIF
Lossy and lossless
Yes, smooth
Yes
Smallest
About 95%
JPEG
Lossy only
No
No
Medium
Universal
PNG
Lossless only
Yes, smooth
No (not normally)
Large
Universal
GIF
Lossless, 256 colours
On or off only
Yes
Poor for photos
Universal
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.
PNG
74.9%
JPEG
68.8%
WebP
23.1%
GIF
13.2%
AVIF
1.7%
SVG (vector)
68.4%
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
It offers both lossy and lossless compression in a single format, so it can replace both JPEG and PNG.
It supports smooth alpha transparency, even with lossy compression. JPEG can’t do that at all, and PNG can only do it with a large file size.
It supports animation, with far smaller files than GIF.
It typically produces files around 25–35% smaller than JPEG at a similar visual quality, and lossless files around a quarter smaller than PNG, although results vary with the image.
It’s fast to encode and decode, and it’s well supported by tools and CDNs.
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.
It’s based on the AV1 video codec, and it generally delivers the smallest files of any format here. Files are often around 30–50% smaller than JPEG, and usually smaller than WebP, depending on the image.
It supports lossy and lossless compression, smooth alpha transparency and animation.
It supports higher colour depth, wide colour gamut and HDR, which the older formats can’t offer.
It holds up well at low quality settings, especially in smooth areas such as skies and gradients.
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
Lossy compression only. A quality setting (0 to 100) trades detail for file size. For web photos, a value somewhere around 70–85 is often a good starting point.
It handles millions of colours, which suits photographs.
It has no transparency and no animation.
A progressive option lets the image appear in a rough form first, then sharpen as it loads.
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
Lossless compression, so it’s pixel-perfect, with no quality lost however often it’s saved.
Smooth alpha transparency, with soft, anti-aliased edges.
It comes in a palette version (up to 256 colours, small files) and a full-colour version (millions of colours, larger files).
It keeps sharp edges and text crisp.
Ordinary PNG files have no animation. (An APNG extension exists, but it’s rarely used.)
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
It’s limited to a palette of 256 colours per frame. That gives lossless compression within the palette, but poor results for photographs.
It supports animation and looping, which is the reason it has survived.
Transparency is either on or off. There are no semi-transparent pixels, so edges look jagged on varied backgrounds.
It has no sound.
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.
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>
Put the alt, width and height attributes on the img, and they’ll apply to the whole picture.
Use loading="lazy" for images below the first screen, but don’t lazy-load the main image at the top of the page, because that will delay it.
Use srcset and sizes to offer smaller versions of an image to smaller screens.
Name your files according to the rules in cheat sheet 1, so use lowercase and hyphens, and make the names descriptive.
Getting the balance right
Do this
Why
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 it
Avoids losing quality through repeated re-saving
Strip unneeded metadata such as camera and location data
Saves bytes and protects privacy
Lazy-load images below the fold
Visitors 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
Mistake
Fix
Saving a photograph as PNG
Use AVIF, WebP or JPEG
Using JPEG for logos, text or flat graphics
Use SVG, PNG or lossless WebP, to avoid blocky artefacts
Uploading a 4000-pixel camera photo and shrinking it with CSS
Resize the file itself to the displayed size
Using an animated GIF for a long clip
Use video, or animated WebP
Converting a JPEG to PNG to “improve” it
It can’t restore lost detail and only makes the file bigger
Re-saving a JPEG again and again
Export from the original every time
AVIF or WebP with no fallback
Use <picture> with a JPEG or PNG img
Lazy-loading the top-of-page image
Load it normally so it appears quickly
Missing alt, width or height
Add all three, so the page is accessible and doesn’t jump as it loads
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.