Xerobit
Encoding & Crypto

Data URI Size Limits and When Inlining Base64 Hurts Performance

Data URI size limits in Chrome, Firefox and Safari, what base64 costs after gzip (measured on PNG, WOFF2 and SVG), when inlining loses, and code to build one in browser and Node.

MA Mian Ali Khalid Updated Nov 2, 2026 6 min read
Free tool
Base64 Encoder / Decoder
Encode and decode Base64 strings and files. Client-side, safe for sensitive data.
Open tool →
On this page ⌄
  1. The format
  2. Size limits by browser
  3. Email clients
  4. What base64 costs after compression
  5. SVG: skip base64
  6. Build one in the browser and Node
  7. FAQ
  8. Tested

Browsers will accept very large data URIs, so the limit is not the problem. The real limits are what base64 costs after compression and the fact that an inlined file can never be cached on its own. A data: URL is fine for a 1 KB icon on every page and a bad idea for a 100 KB image. The numbers below are measured, and the one rule that was not measured is labelled.

The format

data:[<media-type>][;base64],<data>

Without ;base64 the data is percent-encoded text. With it, the data is base64. If the media type is left out it defaults to text/plain;charset=US-ASCII. Typos were tested in Chrome 156 using a 100 KB PNG:

SourceResult
data:image/png;base64,<png>loaded 1200x630
data:;base64,<png> (no MIME type)loaded (Chrome sniffed the image)
data:image/png,<base64 text> (flag missing)error
data:image/png;base46,<png> (typo)error

MDN says an invalid parameter or a typo in base64 is ignored without an error message, which matches the second failure: the string was treated as raw text, not decoded. If an inlined image will not render, check the flag first.

Size limits by browser

From MDN (read 2026-11-02): browsers are not required to support any particular maximum, Chromium and Firefox limit data URLs to 512 MB, and Safari (WebKit) to 2048 MB. Firefox raised its limit from 256 KB to 32 MB in version 97 and to 512 MB in version 136, so older advice about a 32 KB or 256 KB cap refers to browsers you can ignore (Internet Explorer's old small cap is not verified). The practical side was confirmed in Chrome 156: fetch() of a data URI with a 60 MB base64 payload returned 47,185,920 bytes without error.

Navigating the address bar or location.href to a data: URL is blocked in all modern browsers as an anti-phishing measure (MDN). In Chrome 156 setting location.href = 'data:text/html;base64,...' left the page on about:blank. Data URIs are for sub-resources (<img>, CSS url(), fetch), not for pages.

The limit you will actually hit is not the browser's. It is HTML or JSON size, an HTTP header or cookie limit if you put one in a header, or a CMS or email platform that truncates long attributes.

Email clients

caniemail.com lists base64 <img> support at about 81% of tracked clients. Gmail, Apple Mail, Yahoo and the Outlook apps are marked as supported (Gmail and Yahoo since 2020), Outlook for Windows 2007 to 2019 does not render base64 GIFs, GMX and WEB.DE only render PNG, and Orange webmail and some others do not support it at all. That page was last tested in February 2020, so treat it as a guide, not as current truth. For email the usual advice is a hosted image or a CID attachment, and no email client was tested.

What base64 costs after compression

Base64 turns 3 bytes into 4, so the raw overhead is 33%. HTML and CSS are normally gzipped or brotli-compressed on the wire, though, and that recovers most of it. Real files from this site were measured with Node's zlib (gzip level 9, brotli default):

FileRawgzip of rawbase64gzip of base64brotli of base64
logo.png4,0792,3555,4402,5102,480
Geist Mono WOFF242,20842,24156,28042,40542,323
Geist Pixel WOFF220,91220,94027,88421,01020,976
OG image PNG (1200x630)102,12086,897136,16090,96990,220

So compressed, base64 of an already-compressed file costs about 0.4% to 6.6% extra on the wire, not 33%. The 33% shows up in memory, in the parsed HTML or CSS, and wherever the page is not compressed. The wire cost is therefore not the reason to avoid inlining. The reasons are these:

  1. No separate caching. A linked font is downloaded once and reused on every page and visit. An inlined font is re-sent with every HTML response, so a 42 KB font in 100 page views is 4.2 MB, not 42 KB.
  2. Render blocking. Data inside a stylesheet makes the stylesheet bigger, and a stylesheet blocks rendering until it is parsed. This is reasoning, not a measurement.
  3. No prioritisation. An inline image cannot be lazy-loaded or deprioritised; it loads with the document.
  4. Duplicates. The same icon in ten CSS rules is ten copies, though gzip squeezes repeats well.

When inlining wins: a handful of tiny assets (roughly 1 to 2 KB or less each, a rule of thumb, not a tested threshold) that appear on every page, where saving a request on a cold first load matters, or where you need a single self-contained file (an HTML email template for a client that supports it, a single-file report, a CSS file shipped in a library). HTTP/2 made extra requests cheap, which removed most of the old argument for inlining; Request cost was not benchmarked, so no break-even number is given.

SVG: skip base64

SVG is text, so base64 is the worst choice. The 663-byte site favicon was measured as a data URL in three forms (all three rendered in Chrome 156):

FormLengthAfter gzip
data:image/svg+xml;base64,...910394
data:image/svg+xml, + encodeURIComponent(svg)1,232270
minimal escaping (" to ', escape % # < >)757242

Minimal escaping is smallest both raw and compressed. In CSS wrap the URL in quotes. For SVG icons you control, it is also the easiest to read and edit later.

Build one in the browser and Node

Browser, for a file the user picked or a Blob (verified in Chrome 156, output data:text/plain;base64,aGVsbG8=):

const url = await new Promise((resolve, reject) => {
  const r = new FileReader();
  r.onload = () => resolve(r.result);
  r.onerror = reject;
  r.readAsDataURL(new Blob(['hello'], { type: 'text/plain' }));
});

Node:

const fs = require('fs');
const png = fs.readFileSync('logo.png');
const url = 'data:image/png;base64,' + png.toString('base64');

Do not use btoa() on arbitrary text, since it throws on characters above Latin-1; the Base64 tool handles text and files.

FAQ

What is the maximum length of a data URI? No standard maximum. Chromium and Firefox cap at 512 MB and Safari at 2048 MB according to MDN.

Can I open a data URL in the address bar? Not as a page; top-level navigation to data: is blocked in modern browsers.

Do data URIs work in email? Often, not always. See the caniemail summary above and test your target clients.

Is base64 or percent-encoding better for SVG? Percent-encoded or minimally escaped; it is smaller after compression (270 and 242 bytes versus 394 for the example above).

Tested

2026-11-02: Chrome 156.0.8078.48 headless via playwright-core (image loads, typos, 60 MB fetch, top-level navigation, FileReader), Node v25.8.0 zlib for the compression table. MDN data URL page and caniemail.com were read via web fetch. Not tested: Firefox and Safari limits (taken from MDN), any email client, PDF embedding via data URI.

Related tools

Written by Mian Ali Khalid. More guides in Encoding & Crypto.