On this page
You add placeholder="blur" to a gallery of remote images, paste in a blurDataURL from somewhere, and view source. Every <img> now carries more than a kilobyte of inline style, and the page has 40 of them. Is that the placeholder's fault, or Next.js's? Would WebP be smaller? Is ThumbHash the fix everyone says it is?
We built a blur placeholder generator, so we measured. The short version: a 4-pixel PNG is mostly packaging, lossy formats are smaller but shift colours, Chrome hides a 456-byte colour profile in canvas WebP and JPEG output, and ThumbHash's 28 characters can turn into 4 KB if you decode them in the wrong place.
Setup. The 12 PNG photos from the public Kodak lossless true colour suite (10 landscape at 768×512, 2 portrait at 512×768). Each was decoded and downscaled the way our tool does it (Chrome's createImageBitmap to 256 px, then an area-average to 100 px), and every format was produced by the tool's own code. WebP and JPEG came from canvas toDataURL(type, 0.7) in Chrome 158 on Linux. No saturation boost, so pixels compare exactly. Sizes are data-URL characters, which is what lands in your HTML.
What Next.js does with your blurDataURL
The usual setup for a remote image looks like this. The data URL is a real 4 px placeholder for Kodak image 16:
import Image from "next/image";
// Remote src: allow its host in images.remotePatterns (next.config).
// 4×3 PNG made at build time (or pasted from the tool): 162 characters.
const blurDataURL =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAIAAAA7ljmRAAAAL0lEQVR4AWOoba8vqGuYNn9C68R2hqyMyPTMmIKc8Lr6XAZbW2NzK2MPLzsPbwcAPtUOPJbCAWYAAAAASUVORK5CYII=";
export function Hero() {
return (
<Image
src="https://images.example.com/kodim16.jpg"
width={768}
height={512}
alt="Palm trees on a small island under clouds"
placeholder="blur"
blurDataURL={blurDataURL}
/>
);
}We server-rendered that component with react-dom/server against Next.js 16.4.6. Here is the <img> it produced, shortened:
<img alt="…" loading="lazy" width="768" height="512" decoding="async" data-nimg="1"
style="color:transparent;background-size:cover;background-position:50% 50%;
background-repeat:no-repeat;background-image:url("data:image/svg+xml;charset=utf-8,
%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 768 512'%3E
%3Cfilter id='b' color-interpolation-filters='sRGB'%3E
%3CfeGaussianBlur stdDeviation='20'/%3E … %3CfeGaussianBlur stdDeviation='20'/%3E
%3C/filter%3E%3Cimage … preserveAspectRatio='none' style='filter: url(%23b);'
href='data:image/png;base64,…'/%3E%3C/svg%3E")" src="…"/>Next doesn't show your image directly. It wraps it in an SVG (getImageBlurSvg in next/dist/shared/lib/image-blur-svg.js) that stretches it to the box and runs it through feGaussianBlur stdDeviation='20' twice. That wrapper costs 922 characters per image before your data URL is even counted: the same tag rendered without a placeholder is 156 characters, with the 162-character PNG it is 1,240.
The detail that matters is the viewBox, because the blur radius is measured in its units:
- Static imports (
import pic from "./pic.jpg"): Next makes the placeholder itself, 8 px on the long side at quality 70 (BLUR_IMG_SIZEandBLUR_QUALITYinnext-image-loader/blur.js), and sets the viewBox to 40× that, 320×200 for a 3:2 photo. A 20-unit blur is 6% of the width. - A blurDataURL you supply: the viewBox is your
widthandheightprops. Atwidth={768}the same blur is 2.6% of the width; atwidth={3000}, 0.7%. Withfilland no size there is no viewBox, and the blur is 20 CSS pixels.
So for remote images, the blur is weaker than for static imports, and its strength depends on a prop you set for layout reasons. The Image docs say “a very small image (10px or less) is recommended” and “A large blurDataURL may hurt performance.” One more cost: next/image is a client component ('use client' at the top of next/dist/client/image-component.js), so when a Server Component renders it, its props, blurDataURL included, are also serialized into the RSC payload in the page.
A 4×3 PNG is mostly packaging
Shrink a 768×512 photo to 4 px wide and you get 4×3 pixels: 36 bytes of RGB, 39 with PNG's filter byte per row. The PNG file is 104 bytes. The difference is fixed structure: the 8-byte signature, the IHDR chunk (25 bytes), and 12 bytes each of chunk framing for IDAT and IEND. That's 57 bytes before any pixel data.
Compression doesn't help at this size. Our encoder tries every row filter and keeps the smaller of a stored or Huffman-coded deflate stream; the IDAT came out at 47 or 48 bytes, larger than the 39 raw bytes, because zlib adds a 2-byte header and a 4-byte checksum. Node's zlib.deflateSync at level 9 on the same rows gave 47 to 50 bytes. Base64 then adds a third, and the data:image/png;base64, prefix 22 characters.
| Width | Pixels (landscape) | PNG bytes | Data URL chars | Portrait (512×768) |
|---|---|---|---|---|
| 4 px | 4×3 | 104–105 | 162 | 4×6: 210–214 chars |
| 8 px | 8×5 | 185–193 | 270–282 | 8×12: 510–514 chars |
| 16 px | 16×11 | 513–607 | 706–834 | 16×24: 1,674–1,682 chars |
At 4 px, all ten landscape photos produced exactly 162 characters. The image content barely registers; the container is the size.
WebP is smaller, JPEG isn't, and both shift colour
Lossy WebP is the obvious next step. We encoded the same 4 px pixels through canvas WebP and JPEG, decoded the results back in Chrome, and compared them with the exact pixels the PNG stores. Error is mean absolute difference per RGB channel on a 0–255 scale, averaged over the 12 photos.
| 4 px, 12 photos | As the browser encodes it | Metadata stripped | Mean error | Worst pixel |
|---|---|---|---|---|
| PNG | 162–214 chars | (none to strip) | 0 | 0 |
| WebP q0.7 | 743–767 | 103–123 | 6.79 | 44 |
| JPEG q0.7 | 1,051–1,075 | 395–419 | 7.50 | 38 |
Stripped WebP is a quarter to a half smaller than PNG. But on a 4×3 image every pixel is a large share of the picture, and a channel off by 44 out of 255 is a visible hue change. At 8 px it got worse, not better: WebP's worst pixel was off by 60, JPEG's by 78. VP8 encodes colour at half resolution (4:2:0), which is a lot to lose when there are only 12 pixels.
JPEG loses on both counts. Even stripped, its two quantization tables (67 bytes each), frame header and four Huffman tables outweigh the pixels. The scan, header included, was 25 to 38 bytes.
The 456 bytes Chrome puts in your WebP
The “as the browser encodes it” column is not a typo. Here's where the bytes go. A WebP file is a RIFF container: RIFF, a little-endian size, WEBP, then chunks of a 4-byte tag, a 4-byte size and the payload, padded to an even length (RFC 9649 §2.3–2.4). This lists them:
// Paste into a Chrome DevTools console.
const c = document.createElement("canvas");
c.width = 4;
c.height = 3;
const ctx = c.getContext("2d");
ctx.fillStyle = "#776c58";
ctx.fillRect(0, 0, 4, 3);
ctx.fillStyle = "#4a6f8c";
ctx.fillRect(0, 0, 4, 1);
const url = c.toDataURL("image/webp", 0.7);
const b = Uint8Array.from(atob(url.split(",")[1]), (ch) => ch.charCodeAt(0));
const dv = new DataView(b.buffer);
const tag = (o) => String.fromCharCode(...b.subarray(o, o + 4));
console.log(url.length, "chars,", b.length, "bytes");
for (let o = 12; o + 8 <= b.length; ) {
const n = dv.getUint32(o + 4, true); // chunk size, little-endian
console.log(` ${tag(o)} ${n} bytes`);
o += 8 + n + (n & 1); // odd chunks carry one padding byte
}743 chars, 538 bytes
VP8X 10 bytes
ICCP 456 bytes
VP8 36 bytesThe image is 36 bytes. Chrome wrapped it in the extended format: a VP8X header whose ICC flag is set, and an ICCP chunk with a 456-byte ICC profile. Reading its header, it's a display-class RGB profile with the description “sRGB”. JPEG gets the same profile in an APP2 segment (ICC_PROFILE identifier, then the 456 bytes; 472 with its header). One quirk we saw: a canvas you never drew on is encoded without the profile; once you draw, it's there.
You can drop it. The RFC says that without an ICCP chunk “sRGB SHOULD be assumed” (§2.7.1.4), and CSS Color 4 says “untagged images must be treated as being in the sRGB color space” (§3.5). For an opaque, still, lossy image, the minimal file is just the RIFF header and the VP8 chunk (§2.5, simple format):
// Opaque, still, lossy WebP only: keep the "VP8 " chunk, drop VP8X and ICCP.
function stripWebp(b) {
const dv = new DataView(b.buffer, b.byteOffset, b.byteLength);
const tag = (o) => String.fromCharCode(...b.subarray(o, o + 4));
for (let o = 12; o + 8 <= b.length; ) {
const n = dv.getUint32(o + 4, true);
if (tag(o) === "VP8 ") {
const chunk = b.subarray(o, o + 8 + n + (n & 1));
const out = new Uint8Array(12 + chunk.length);
out.set(b.subarray(0, 12)); // "RIFF" <size> "WEBP"
new DataView(out.buffer).setUint32(4, out.length - 8, true);
out.set(chunk, 12);
return out;
}
o += 8 + n + (n & 1);
}
return b; // lossless (VP8L) or alpha: leave it alone
}
const slim = stripWebp(b);
const slimUrl = "data:image/webp;base64," + btoa(String.fromCharCode(...slim));
console.log(slimUrl.length, "chars after stripping");
// Same pixels? Decode both and compare.
const read = async (u) => {
const bmp = await createImageBitmap(await (await fetch(u)).blob());
const k = new OffscreenCanvas(4, 3).getContext("2d");
k.drawImage(bmp, 0, 0);
return k.getImageData(0, 0, 4, 3).data;
};
const [x, y] = await Promise.all([read(url), read(slimUrl)]);
console.log("identical pixels:", x.every((v, i) => v === y[i]));99 chars after stripping
identical pixels: true743 characters down to 99, same pixels. Images with alpha need the VP8X and ALPH chunks kept, with the ICC bit cleared in the flags; our tool's slimWebp handles that case and the JPEG one (it drops APP0, APP1, APP2 and comments). If you generate placeholders with sharp on a server, sharp leaves metadata out unless you ask for it with withMetadata(); this is a browser-canvas problem.
How close does each one look?
Byte counts don't say what the placeholder looks like. To compare, we rendered each one at 768×512 in Chrome the way it is shown in practice (the Base64 formats and ThumbHash through Next's SVG at width={768}, BlurHash decoded at 32 px wide and stretched, the colour as a fill), and measured mean absolute error against the real photo. No placeholder can show texture, so nothing gets near zero; lower is closer.
| Placeholder | Size | Mean error vs photo |
|---|---|---|
| Average colour | 7 chars | 38.55 |
| BlurHash 4×3 | 28 chars | 30.76 |
| WebP 4 px, stripped | 103–123 chars | 29.76 |
| PNG 4 px | 162–214 chars | 28.67 |
| ThumbHash | 28 chars | 28.01 |
| PNG 8 px | 270–514 chars | 25.48 |
| PNG 16 px | 706–1,682 chars | 22.36 |
8 px was closer than 4 px on all 12 photos, about 11% on average, for 1.7× the characters on landscape images and 2.4× on portrait. Plaiceholder defaults to 4 (size = 4 in its v3 source), and so do we. On a page with dozens of images we'd keep 4; for one hero image, 8 is cheap.
Next's blur barely moved this number. A 4 px PNG simply stretched by the browser scored within 0.2 of the same PNG through Next's filter. What the filter fixes is shape: stretched by itself, a 4×3 image shows the faint cross-shaped creases of bilinear scaling, and the blur softens them into a smooth wash.
ThumbHash vs BlurHash
Both encode a few frequency components as a short string you can keep in a database column next to width and height. On our 12 photos both were exactly 28 characters: BlurHash at its README's recommended 4×3 components (“We usually go with 4 by 3”), and ThumbHash as 21 bytes in Base64. ThumbHash's README makes four claims against BlurHash: more detail in the same space, aspect ratio encoded, more accurate colours, and alpha support. What we could check:
- Detail and colour. ThumbHash was closer to the photo than BlurHash on all 12, and closer than a 162-character 4 px PNG on 7 of 12. On Kodak 16 (palm trees over dark water), BlurHash decoded a near-black blue blob into the water at the bottom; the darkest decoded pixel was
rgb(0, 0, 29). We reproduced that with the npmblurhash2.0.5 package, not just our port, so it comes from the format, not our code. - Aspect ratio, approximately. ThumbHash picks its component counts from the shape, so you can recover it, roughly. For a 3:2 photo it said 1.400, not 1.5. Still store width and height.
- Alpha. ThumbHash has an optional alpha channel. BlurHash's README doesn't mention transparency; it encodes RGB only, so our tool composites transparent images onto a background first.
- Configurability. ThumbHash's README names its own drawback: “the parameters of the algorithm are not configurable.” BlurHash lets you trade length for detail, 1 to 9 components each way. ThumbHash also refuses input larger than 100×100 (
doesn't fit in 100x100), so you downscale first.
The catch with both is that a browser can't display them. You need a decoder, and where you run it decides what you saved. Here's the ThumbHash package decoding a stored hash:
import { thumbHashToDataURL, thumbHashToApproximateAspectRatio, thumbHashToRGBA } from "thumbhash";
// The ThumbHash for Kodak image 1 (768×512), as stored in a text column.
const stored = "2hgGDYB4dWiPd5dleGiIl1lvo/JE";
const hash = Uint8Array.from(atob(stored), (c) => c.charCodeAt(0));
const { w, h } = thumbHashToRGBA(hash);
console.log(hash.length, "bytes; decodes to", w, "x", h);
console.log("aspect ratio ≈", thumbHashToApproximateAspectRatio(hash).toFixed(3));
const url = thumbHashToDataURL(hash);
console.log(url.slice(0, 22), "…", url.length, "chars");21 bytes; decodes to 32 x 23
aspect ratio ≈ 1.400
data:image/png;base64, … 4218 chars21 bytes became a 4,218-character data URL: thumbHashToDataURL writes an uncompressed 32×23 PNG. Do that on the server and pass it as blurDataURL, and you ship 26 times the bytes of a 4 px PNG. Compressed with Brotli at quality 11, the 12 decoded ThumbHashes came to 26,400 bytes; the 12 PNGs to 834.
A client component doesn't fix it on its own, because client components also render on the server. To keep the HTML at 28 characters, decode after hydration:
"use client";
import { useEffect, useState } from "react";
import Image, { type ImageProps } from "next/image";
import { thumbHashToDataURL } from "thumbhash";
type Props = Omit<ImageProps, "placeholder" | "blurDataURL"> & { thumbhash: string };
export function ThumbImage({ thumbhash, alt, ...rest }: Props) {
// Decode in the browser: the HTML carries 28 characters, not ~4 KB.
const [blur, setBlur] = useState<string>();
useEffect(() => {
const bytes = Uint8Array.from(atob(thumbhash), (c) => c.charCodeAt(0));
setBlur(thumbHashToDataURL(bytes));
}, [thumbhash]);
return <Image {...rest} alt={alt} placeholder={blur ? "blur" : "empty"} blurDataURL={blur} />;
}The trade-off is timing: this placeholder appears only after your JavaScript runs, while a Base64 PNG paints with the first HTML. ThumbHash wins when the string travels through an API or a database and the client decodes it anyway (a feed, a mobile app). For server-rendered pages, the 4 px PNG is hard to beat.
No JavaScript at all: colour, CSS, SVG
- Average colour, 7 characters as
background-color. It was the least faithful in our table and worst on images with two big regions: on Kodak 20 its error was 83, against 31 for the 4 px PNG. Still a big step up from an empty box, and nearly free. - CSS gradients: one hard-stop
linear-gradientper row of a 4×3 grid plus a CSS blur, 411 characters as our tool writes them. Paints with the HTML, no image decode. - Inline SVG: an 8-pixel grid of
<rect>s underfeGaussianBlur, 2,797 characters URL-encoded. Readable and works in anysrc, but it's the largest option here.
What we'd use, and our tool's limits
- Server-rendered Next.js with remote images: a 4 px PNG as
blurDataURL, 162 characters for a 3:2 image. Exact colours, no decoder. - Bytes really matter and you can live with colour drift: WebP, with the ICC chunk stripped. Without stripping it's 4.6 times the PNG.
- Placeholders stored in a database or sent in API responses: ThumbHash, decoded on the client.
- Static imports: let Next do it.
Where our own numbers come with caveats:
- The Base64 image is made in your browser. Our PNG encoder is exact, but its bytes differ from what sharp (and so plaiceholder) writes, and WebP and JPEG depend on the browser's encoder. Firefox and Safari may give other sizes.
- Sizing differs from plaiceholder for portrait images. We set the width and derive the height (4×6 for a 2:3 photo); plaiceholder fits the image inside a 4×4 box (3×4).
- Defaults. Our tool, like plaiceholder v3, boosts saturation 1.2× by default, because averaging greys colours out. We turned that off for these measurements; at 4 px it changed the PNG length on one photo of 12, by 4 characters.
- The hashes are exact ports of the thumbhash and blurhash packages and match their output, but you still ship one of those decoders to show them.
Our blur placeholder tool shows all six formats for an image side by side, with every Base64 format's real length, and writes the Next.js, React or HTML code. Nothing is uploaded.