1001Ferramentas
๐Ÿ”—Validators

Data URI Validator

Validate Data URI format (data:[mediatype][;base64],data) and show mediatype, encoding and payload size.

Data URIs: embedding bytes directly in HTML, CSS and JSON

A data: URI is a URL whose body is the resource โ€” there is no host, no path, no network request. The scheme was standardized in RFC 2397 (1998) and is supported by every modern browser, email client and HTTP-aware tool. It is the canonical way to inline a small image, an SVG icon or a short JSON snippet into HTML, CSS or JavaScript without spawning an additional HTTP roundtrip.

The trade-off is straightforward: you eliminate a network request and you make the asset trivially cacheable as part of the parent document, but you pay a ~33% size penalty (Base64 overhead) and you give up independent caching. Used wisely, data URIs are an elegant optimization; used carelessly, they bloat HTML/CSS files and starve cache hit rates.

Syntax (RFC 2397)

data:[<media-type>][;base64],<data>
  • media-type: optional MIME type like image/png or application/json. Defaults to text/plain;charset=US-ASCII when omitted.
  • ;base64: optional flag. When present, the payload is decoded as Base64. When absent, the payload is decoded as URL-percent-encoded text.
  • data: the actual bytes, either percent-encoded or Base64-encoded.

Real examples:

data:text/plain,Hello%20World
data:application/json,{"hello":"world"}
data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'.../>
data:image/png;base64,iVBORw0KGgoAAANSUhEUgAA...
data:text/html;charset=utf-8;base64,PGgxPkhlbGxvPC9oMT4=

Common use cases

  • CSS background images: background: url("data:image/svg+xml;base64,...") avoids a separate HTTP request for tiny icons and gradients.
  • Inline SVG favicons: <link rel="icon" href="data:image/svg+xml,<svg...><text>๐Ÿš€</text></svg>"> โ€” the emoji favicon trick popularized in 2020.
  • Email HTML: inline images so the message renders offline, without a tracking pixel call.
  • Client-side downloads: a.href = "data:text/csv,..." + a.download = "report.csv" lets users save a generated file with zero server involvement.
  • Test fixtures: embedding small images or JSON payloads inside test files makes the suite self-contained.

Performance: when data URIs help and when they hurt

Embedding a 200-byte SVG icon inline is almost always a win โ€” you trade a 200-byte payload for a TCP handshake and TLS round-trip you would otherwise pay. Embedding a 200KB hero image is almost always a loss: you bloat the HTML/CSS, prevent the browser from caching the image independently, and block first paint.

Rules of thumb:

  • Inline assets smaller than ~2KB. Above that, use a real URL with loading="lazy".
  • Prefer URL-encoded SVG over Base64 SVG โ€” both work, but URL-encoded is ~30% smaller for text-heavy payloads.
  • Never inline anything that should be cached across pages (logos, sprite sheets, web fonts).
  • Watch the browser limit: Chrome caps individual data URLs at around 2MB; older Safari was much stricter.

Security and CSP considerations

Data URIs can be a vector for XSS and phishing: data:text/html can render arbitrary markup, and historically attackers used data: URLs in phishing campaigns to host fake login pages without registering a domain. Mitigations:

  • CSP: restrict data: usage per directive. A typical policy allows img-src 'self' data: but blocks frame-src data: and object-src data:.
  • Chrome and Firefox block top-level navigation to data:text/html URLs since 2018 to thwart phishing.
  • Sandboxed iframes: when you really need to render arbitrary data:text/html, isolate it with sandbox="allow-scripts" and no allow-same-origin.

Email clients and the cid: alternative

Outlook (especially Outlook 2007-2019 with Word as the renderer) strips many data: URIs in HTML email bodies, which breaks logos and inline graphics. The portable alternative for email is the cid: URI scheme (RFC 2392), which references a MIME attachment by its Content-ID. Modern transactional-email providers (Postmark, SendGrid, AWS SES) handle the cid: wrapping automatically.

Tooling

  • Browser DevTools: paste any data URI into the address bar โ€” the browser renders it natively.
  • Node.js: Buffer.from(payload).toString('base64') for encoding; npm dataurl and data-urls for full parsing.
  • Webpack / Vite: the asset/inline module type emits data URIs automatically for assets below a threshold.
  • Bash: base64 -w 0 image.png on Linux, base64 -i image.png on macOS.

FAQ

Are data URIs cacheable? Not independently. They are cached as part of the document that contains them, but the browser cannot reuse them across pages or sites.

What is the maximum size? The spec does not impose a limit, but browsers do. Chrome and Firefox handle up to ~2MB comfortably; Safari historically capped earlier. Treat ~32KB as a safe upper bound for cross-browser reliability.

Are data URIs safe? They are inert for image, font and CSS contexts. For text/html and application/javascript they execute as code โ€” use CSP data: restrictions and sandboxed iframes when rendering untrusted content.

When should I prefer URL-encoded over Base64? For text-heavy payloads like SVG and JSON โ€” URL-encoded is typically 20-30% smaller. Base64 wins for binary data (PNG, JPEG, fonts) where percent-encoding would explode in size.

Does this tool send the data URI to a server? No. Parsing and validation run entirely in the browser. Nothing is uploaded or logged.

Related Tools