The same 800 by 800 image, converted on 2026-09-02: 596797 bytes as a PNG,
239860 as a JPEG at quality 80, 173114 at quality 60, and 113270 as HEIC. One
picture, and the largest version is five times the smallest, decided entirely by
the format and a number nobody sees.
The choice is not taste. A photograph belongs in a lossy format because the
compression discards detail the eye does not miss. A screenshot, a logo or
anything with flat colour and hard edges belongs in PNG or SVG, because lossy
compression puts visible fringes around exactly those edges and, on flat colour,
often produces a larger file than the lossless version.
The attributes that stop the page jumping
width and height on an img are not
sizing instructions, they are the aspect ratio. Give both and the browser
reserves the right shape of space before the file arrives, so nothing below
moves when it loads. Leave them off and everything under the image jumps down
when it appears, which is the single most common cause of a page moving under a
reader's finger.
HTML + CSS together
How attributes and responsive rules prevent layout jumps
HTML dimensions and CSS scaling do two different jobs and neither overrides the other.
- HTML width and height
- CSS max-width: 100% and height: auto
- HTML width and heightSets the aspect ratio so the browser reserves exact vertical space before download
- CSS max-width: 100% and height: autoScales the rendered box smoothly to fit narrow containers while keeping that ratio
Omitting width and height is what makes text jump under a reader's finger as soon as the image file finishes arriving.
Interactive Practice Lab
Edit and run this snippet directly in your browser (zero setup)
<article style="padding:14px;border:1px solid color-mix(in srgb,currentColor 24%,transparent);border-radius:12px"> <h3 style="margin:0 0 6px">Semantic Card</h3> <p style="margin:0 0 10px;opacity:.85">Edit this HTML and click Run to preview live.</p> <button onclick="console.log('Button clicked at', new Date().toLocaleTimeString())">Test Event</button></article>Live Big-O Complexity & Binary Search Race Lab
Compare complexity curves at scale and watch Linear vs Binary Search race live.
CSS still controls the actual size:img { max-width: 100%; height: auto } alongside the attributes gives
you both the reserved space and a responsive image. The two are not in conflict
and the attributes are not obsolete, which is a widely repeated mistake from
about 2015.
The alt attribute has three states, not two
- A description, for an image carrying information: what it shows, not that it
is an image alt="", exactly empty, for decoration. It tells assistive
technology to skip the image entirely, which is what you want for a border or a
texture- No alt attribute at all, which is the one to avoid: some screen readers then
read the filename, so the reader hears the characters oftile-hero-final-2.png
The distinction between the first two is a judgement about the page rather
than about the image. The same photograph is decorative next to a paragraph that
already describes it and informative when it is the content.
Three states, not two
How assistive technology handles each alt attribute state
Choosing between descriptive text and an empty string depends on the surrounding page, while omitting alt leaves readers with raw filenames.
- Descriptive alt3
- Image carries new information
- Describe what the picture shows
- Do not write 'image of'
- Empty alt=""3
- Pure border or texture
- Nearby prose already describes it
- Screen reader skips cleanly
- No alt attribute3
- Avoid this state
- Reader may spell out filename
- Reads tile-hero-final-2.png aloud
The same photo is decorative next to a full caption and informative when it stands as the content itself.
Serving more than one file
srcset with sizes lets the browser choose among
several widths of the same image, and it chooses using information no server
has: the device pixel ratio and the actual laid out width. A<picture> element with several<source type="..."> entries does the same for formats, so a
browser that supports a newer one takes it and the rest fall through to theimg.
Browser-side selection
Three markup tools for shipping the right image file
The browser knows device pixel ratio, layout width, and supported formats before requesting a single byte.
- srcset and sizesPicks the right pixel width for screen density and laid-out column size
- picture and source typeServes newer formats to supporting browsers and falls through to img
- loading="lazy" below foldDefers off-screen assets while keeping above-the-fold images immediate
HTML img fallback
Adding loading="lazy" to the top hero image delays the exact asset the reader opened the page to see.
loading="lazy" is the other attribute worth adding, on images
below the fold only. On an image at the top it delays the thing the reader came
for, which is the opposite of the intended effect and a common way to make a
page measurably worse while believing otherwise.
What to run in 2026
sips is what produced the numbers above, free with macOS, and it
converts and resizes from one command:sips -s format jpeg -s formatOptions 80 tile.png --out tile.jpg. It
replaced opening an editor to check what a format costs, which is a five second
question that nobody asks because the tool is slower than the guess.
The browser's network panel is the second, free in every browser, and it is
the one that tells the truth about what was actually downloaded rather than what
was declared. Sort by size, and the image at the top is nearly always the whole
optimisation. It replaced arguing about page weight without a number.
Where this stalls people
The stall is optimising the format and shipping the wrong dimensions. A
photograph exported at 4000 pixels wide and displayed in a 400 pixel column is
downloading roughly a hundred times the pixels it will show, and no format
choice recovers that. The file is correct, the compression is good, and the page
is still slow.
Pixels shipped vs pixels shown
Why resizing beats recompressing an oversized photo
A 4000-pixel export inside a 400-pixel column transfers roughly a hundred times more pixels than the screen can display.
Image width in pixels
Rendered columnExported file
- Column photo width4004000When natural width is over twice rendered width, resize first
Checking natural width against rendered width in the inspector takes one look and prevents wasted compression tuning.
The check takes one look: compare the image's natural width in the inspector
against the width it is rendered at. If the first is more than about twice the
second, the fix is a resize, not a format. What that does to the page's speed
overall is
why a page feels slow, and what
actually fixes it, the markup around it is
elements that say what they are,
and who that helps, and the sizing rules are
one document, every screen,
inside the structure under every page.