1. Presentation
  2. Images
  3. Basics
  4. What an Image Costs

Presentation · Images 01

What an Image Costs

An image can say in a glance what a paragraph cannot, and it can cost more than everything else on the page put together. Using images well starts with knowing what an image is made of, what it costs to send, and what it is for.

This page sets up the ideas every later page in the section depends on: the size of the problem, the order in which to attack it, the two ways a computer can store a picture, the arithmetic of pixels, the two kinds of pixel a web developer has to keep apart, and the two jobs an image can do on a page.

1. Big bytes, big value

Images are the heaviest thing most pages send. The HTTP Archive crawls millions of sites every month and publishes what it finds in its annual Web Almanac. In the July 2025 crawl, the median home page weighed about 2.9 MB on desktop and 2.6 MB on mobile, and the median home page loaded 1,058 KB of images on desktop and 911 KB on mobile, from around 19 image files.

The median home page, HTTP Archive Web Almanac 2025 (July 2025 crawl)
MeasureDesktopMobile
Total page weight2.86 MB2.56 MB
Image bytes1,058 KB911 KB
Image filesabout 19

Medians hide the tail. A median means half of all home pages send more than this, and the heaviest pages send many megabytes of images, often a single photograph straight from a camera. A phone on a slow or metered connection pays for every one of those bytes in time, battery and money.

The reason images are so heavy is also the reason they are worth it. Images carry information that text carries badly: what a product looks like, where a place is, how a chart trends, who is speaking. They set a mood before a word is read. A page without them is often harder to use, not easier.

So images are both a large cost and a large value, and the evidence cuts both ways. A 2016 study of real-user data by SOASTA and Google found that the number of images on a page was the second-best predictor of whether a mobile visit ended in a sale: visits that converted had loaded 38 percent fewer images than visits that did not. The point is not that images hurt. It is that unnecessary images hurt, because they slow the page down and dilute the ones that matter.

2. The first question: do you need the image?

The techniques for using images efficiently have not changed much in twenty-five years, because the problem has not changed: a picture is a lot of data, and the network is the slowest part of the system. The techniques come in a fixed order, from the most effective to the least:

StepQuestionExamplesTaught on
EliminateDoes this image need to exist at all?Real text instead of text in an image; a CSS gradient or border instead of a decorative file; one strong photograph instead of a carousel of sixThis page, section 6
Reduce the numberCan several images become one, or none?An SVG icon set instead of thirty icon files; a sprite sheet (mostly history now)SVG, Image performance
Reduce the sizeIs each image as small as it can be while still looking right?The right format, a sensible quality setting, no more pixels than the screen will showRaster formats, Images in HTML, Image performance
Load when neededDoes it have to arrive now?Lazy loading below the fold; priority for the hero image; caching so it arrives only onceImage performance

The order matters because the savings multiply. An image you remove costs nothing, however well it would have been compressed. An image you keep but send at the right size and format may be a twentieth of the original. An image that is small and lazy-loaded may never be downloaded at all by a reader who never scrolls to it.

Elimination is the step people skip, because it is a design decision rather than an engineering one. It asks what the image is for. A photograph of the actual product is the content. A stock photograph of smiling people at a laptop, placed above a sign-up form, usually is not: it costs a reader on a slow phone several seconds and tells them nothing. The course's attitude is the same one it takes to every resource: the reader's time and data are not ours to spend carelessly.

3. Raster and vector

A computer can store a picture in two fundamentally different ways.

A raster image (also called a bitmap) is a grid of dots, each with its own color. The file records every dot, or a compressed description of them. JPEG, PNG, GIF, WebP and AVIF are raster formats. A raster image is good at anything photographic, where every dot really is different from its neighbors.

A vector image is a list of drawing instructions: a circle of this radius here, a path through these points, filled with this color. The file records shapes, not dots. On the web, the vector format is SVG (Scalable Vector Graphics), an XML language that browsers draw natively. A vector image is good at logos, icons, diagrams, charts and illustrations: anything made of shapes.

The same circle as a raster and as a vectorOn the left, a circle stored as a raster: a 12 by 12 grid of 144 squares, with the squares inside the circle filled, so its edge is a staircase. On the right, the same circle stored as a vector: one smooth shape described by a single circle element with a center and a radius.raster: 144 stored pixelsthe edge is a staircase of squaresvector: one stored shape<circle cx="60" cy="60" r="60"/>
The raster stores every square, so its quality is fixed when it is made. The vector stores a description, so the browser can draw it sharply at any size.

The difference shows when the image changes size. Scale a raster image up and the browser has to invent pixels that were never stored, so it blurs or turns blocky. Scale a vector up and the browser simply draws the shapes bigger: the edge stays sharp at any zoom and on any screen. That is why vector images are called resolution independent.

The difference also shows in the file size. The Trail Notes logo used across this section is a few circles, paths and two words of text:

The same 480 by 240 logo, as encoded by the site's build script
FileKindBytesAt twice the size
logo.svgVector900The same file, drawn larger
logo.pngRaster, lossless9,752A new file with four times the pixels
logo.webpRaster, lossless6,416A new file with four times the pixels
Trail Notes logo: a gold mountain in a navy circle, with the words Trail Notes.
The logo as SVG, 900 bytes. Zoom the page as far as it goes and the edges stay sharp. The SVG also carries its own prefers-color-scheme media query, something no raster format can do: in dark mode, in browsers that honor the query inside an image, the word "Trail" turns light. (Safari has long ignored it there; SVG and vector images explains.)

Vector is not always the answer. A photograph has no shapes to describe, only millions of slightly different dots, and an attempt to trace one into paths produces a file far larger than a JPEG and still looks wrong. A complex illustration with thousands of paths can also outweigh a raster version. And every vector is turned into pixels in the end: the screen is a grid, so the browser rasterizes the SVG every time it draws it, at whatever size the layout asks for. The vector's advantage is that the rasterizing happens at the last moment, on the reader's screen, at the exact size needed.

The rule of thumb for the rest of the section: SVG for anything drawn, raster for anything photographed. SVG and vector images (page 03 of this section) covers SVG in depth.

4. Pixels, bit depth and pixel math

A pixel ("picture element") is one dot of a raster image. Each pixel stores a color, and the number of bits used to store that color is the image's bit depth:

Bit depthBytes per pixelColorsTypical use
1 bit1/82Black-and-white line art, a transparency mask
8 bits1256 (from a palette)GIF, palette PNG: logos, flat illustrations
24 bits3about 16.7 million (8 bits each of red, green, blue)Photographs: JPEG, PNG, WebP, AVIF
32 bits424-bit color plus 8 bits of transparency (alpha)PNG, WebP or AVIF with soft transparency

From there, the cost of an uncompressed image is simple arithmetic: width × height × bytes per pixel. The deck's classic example is a 640 by 480 screen at 8 bits: 640 × 480 × 1 = 307,200 bytes, about 300 KB, for a picture smaller than a postage stamp on a modern laptop. The daisy photograph this section uses, at 800 by 533 pixels in 24-bit color, is 800 × 533 × 3 = 1,279,200 bytes before compression.

A white daisy in close-up: long white petals around a dense, golden-yellow center of tiny florets, against a soft green background.
800 by 533 pixels: 1,279,200 bytes of raw color, sent here in 11,840 bytes as AVIF, with WebP and JPEG fallbacks for browsers without AVIF. Photograph: Macro flower wallpaper, Free Nature Stock, CC0.

Nobody sends raw pixels. Every web format compresses them, either without losing anything (lossless) or by discarding detail the eye is unlikely to miss (lossy). Raster formats (page 02) explains how. For now, the scale of the difference is the lesson:

The daisy photograph, raw and in five formats, drawn to scaleBars drawn to the same scale. Raw pixels: 1,279,200 bytes, the full width. Lossless PNG: 710,981 bytes, a bit over half. GIF: 215,489 bytes, about a sixth. JPEG at quality 75: 26,669 bytes, a sliver. WebP: 16,468 bytes. AVIF: 11,840 bytes, under one percent of the raw size.raw pixelsPNG (lossless)710,981GIF (256 colors)215,489JPEG26,669WebP16,468AVIF11,8401,279,200 bytes
The same 800 by 533 photograph, in bytes, drawn to scale. The lossy formats are slivers: AVIF is under one percent of the raw pixels.

Two lessons hide in that chart. First, format choice is worth a factor of ten or more: a lossless PNG of a photograph is the right format for the wrong job. Second, once the format is right, the remaining differences between good formats are real but smaller, a factor of about two between JPEG and AVIF here.

Pixels cost memory too

Compression only helps on the wire. To draw an image, the browser decodes it back into raw pixels in memory, usually at four bytes per pixel. The daisy that arrives as 11,840 bytes takes 800 × 533 × 4 = 1,705,600 bytes of memory once decoded. A 4000 by 3000 photograph straight from a phone camera, scaled down by CSS to fill a 400-pixel column, still decodes all 12 million pixels: 48 MB of memory, and the time to decode them, for a picture the reader sees at a hundredth of that. Sending an image larger than it is displayed wastes the network, the processor and the memory, which is why Images in HTML (page 04) spends so long on sending the right size.

5. CSS pixels and device pixels

The word "pixel" means two different things on the web, and keeping them apart is essential.

A device pixel is one physical dot on the screen. A CSS pixel is a unit of length in CSS. It was defined so that one CSS pixel looks about the same size on any screen at a normal viewing distance (formally, 1/96 of an inch), which means it is not tied to the hardware at all. The Values page covers the CSS pixel as a unit.

On an older desktop monitor, one CSS pixel is one device pixel. On a phone or a modern laptop, the screen packs in two or three device pixels for every CSS pixel in each direction, so text and edges look smoother. The ratio is the device pixel ratio, or DPR, and the browser exposes it to JavaScript as window.devicePixelRatio.

One CSS pixel at device pixel ratios of 1, 2 and 3Three squares of the same size, each one CSS pixel. At DPR 1 the square is a single device pixel. At DPR 2 it is divided into a 2 by 2 grid, 4 device pixels. At DPR 3 it is divided into a 3 by 3 grid, 9 device pixels.DPR 11 device pixelDPR 24 device pixelsDPR 39 device pixels
The same CSS pixel at three device pixel ratios. The ratio applies in each direction, so the pixel count grows with its square.

For text and vectors, high DPR is free: the browser draws them at the device's full resolution. For raster images it is not. An image laid out 400 CSS pixels wide covers 400 device pixels at DPR 1, 800 at DPR 2 and 1,200 at DPR 3. To look sharp at DPR 2 the file needs to be 800 pixels wide, and that is four times the pixels, not two.

The lake photograph at two widths, as encoded by the site's build script
FilePixelsRaw bytesJPEG bytesAVIF bytes
lake-800800 × 5331,279,20033,64621,823
lake-16001600 × 10675,121,600119,39874,761

Doubling the width quadrupled the raw pixels and multiplied the compressed bytes by about three and a half: compression does a little better on larger images, because neighboring pixels are more alike. Either way, a "2x" image is far more than twice the cost, and a "3x" image is more again.

This is the tension that responsive images resolve. A reader with a high-density phone benefits from a sharper image; a reader on a desktop monitor gains nothing from it and pays the same bytes. The answer, which Images in HTML (page 04) teaches, is to offer several sizes and let the browser, which knows the screen, choose. The answer is not to send the largest image to everyone. Beyond about DPR 2, most people cannot see the extra detail in a photograph at normal viewing distance, so many sites deliberately cap the density they serve.

6. Content images and presentational images

Every image on a page does one of two jobs, and the job decides how it is written.

A content image is part of what the page says: a product photograph, a diagram that explains, a chart with data, a portrait of the person quoted. Remove it and the reader loses information. Content images belong in the HTML, as <img> (or <picture> or inline <svg>), with alternative text that conveys what the image conveys.

A presentational image is decoration: a background texture, a flourish beside a heading, a photograph used for mood behind a title. Remove it and the page looks plainer but says the same thing. Presentational images usually belong in the CSS, where they can change with the design, the screen and the color scheme without touching the content. When one has to be in the HTML, it gets an empty alt="", which tells assistive technology to skip it.

Content imagePresentational image
The testIf it failed to load, would the reader miss something?If it failed to load, would the page only look plainer?
Where it livesHTML: <img>, <picture>, inline <svg>CSS: background-image, gradients, ::before and ::after
Alternative textSays what the image saysNone in CSS; alt="" if it must be an <img>
Loading priorityHigh when it is the main subject above the foldLow; it can arrive last, or not at all
PrintingPrintsBackground images do not print by default

The same picture can do either job. A photograph of a mountain on a page about that mountain is content; the same photograph faded behind a newsletter sign-up form is decoration. Ask what it is doing on this page.

<!-- Content: the image is the subject, so it is in the HTML with real alt text --> <figure> <img src="lake-800.jpg" alt="Mount Hood, snow-covered, reflected in a still forest lake at dusk." width="800" height="533"> <figcaption>Mount Hood from the lake trail.</figcaption> </figure> <!-- Decoration: the image sets a mood, so CSS supplies it and the HTML stays clean --> <section aria-labelledby="join"> <h2 id="join">Join the Saturday group</h2> … </section> @layer components { section[aria-labelledby="join"] { padding: clamp(1.5rem, 5vw, 4rem); background: linear-gradient(oklch(20% 0.03 260 / 0.6), oklch(20% 0.03 260 / 0.6)), url("lake-800.jpg") center / cover; color: white; } }

The split has consequences the later pages build on. Content images need alternative text that does its job, which Images for people (page 07) teaches. They need to be sized for the layout and the screen, which Images in HTML (page 04) and Fluid and responsive images (page 06) teach. Presentational images can lean on CSS, which Images in CSS (page 05) teaches, and they are the first candidates for the elimination step in section 2.

7. Summary

ConceptKey points
Big bytes, big valueImages are the heaviest resource on the median page: about 1 MB on a home page in 2025. They are also among the most valuable, so the goal is necessary images, sent well.
The first questionEliminate, then reduce the number, then reduce the size, then load when needed. The savings multiply, and elimination saves the most.
Raster and vectorRaster stores a grid of pixels and suits photographs. Vector (SVG) stores shapes, scales without loss, and suits logos, icons and diagrams. Everything is rasterized on screen in the end.
Pixel mathRaw size is width × height × bytes per pixel. Compression shrinks the transfer by ten to a hundred times, but decoding restores the full size in memory, so never send more pixels than are shown.
CSS and device pixelsA CSS pixel is a length; a device pixel is a dot. DPR is the ratio between them. A 2x image has four times the pixels, so offer sizes and let the browser choose.
Content and presentationContent images say something: HTML, real alt text, priority when they matter. Presentational images decorate: CSS, or alt="", and low priority.