Encoding

Data URI / Base64 image

Encode an image into a Data URI (data:image/…;base64,…) for embedding in CSS/HTML, and decode a Data URI or raw Base64 back into a file — all in your browser.

The image preview will appear here.

A Data URI embeds a file's contents (usually an image) directly into HTML or CSS as a Base64 string, instead of linking to a separate file. This removes an extra network request at the cost of a larger document.

How to use it

Common uses

Things to keep in mind

Base64 encoding grows the data by about 33% — for large images, a Data URI is usually a worse choice than a separate file with browser caching.

A Data URI isn't cached separately from the document it's embedded in — it gets re-downloaded along with the page every time.

Article about this tool: Data URI: when to embed images directly in code

Frequently asked questions

When should I use a Data URI instead of a normal image file?

Data URIs are handy for small, frequently-used images like icons or logos where you want to avoid an extra HTTP request, for example embedding an image directly in CSS or inline HTML.

Are there downsides to using Data URIs for images?

Yes. They inflate the surrounding file size (roughly 33% larger than the raw image due to Base64), aren't cached separately by the browser like a real image URL, and many browsers and email clients impose practical size limits on how large a Data URI can be.

Does this tool upload my image anywhere?

No. The image is read and encoded entirely in your browser — it's never sent to a server.

Can I use a Data URI for SVG without Base64?

Yes. SVG is text (XML), so instead of Base64, percent-encoding the special characters is enough: data:image/svg+xml,%3Csvg...%3E. That approach is more compact and stays editable right inside a CSS file.

Can I put a Data URI in an href or background-image?

Yes, a Data URI works anywhere a resource reference is expected — in src, href, background-image in CSS, and even in @import. The syntax and size limits are the same as for an img tag.

Articles: Encoding

Base64: why encoding is needed and how it works

How Base64 turns binary data into ASCII text and where that is actually needed.

Base32: how it differs from Base64 and when it is more convenient

The case-insensitive Base32 alphabet and scenarios where it beats Base64.

URL Encode/Decode: percent-encoding in links

How special characters in URLs and query parameters turn into %XX sequences.

HTML Entities: how to safely output special characters on a page

Why the characters < > & need escaping and how that prevents broken markup.

JWT: token structure and what "decoding" a JWT actually means

The header, payload, and signature of a JWT, and why decoding is not the same as verifying the signature.

Unicode Escape: what \uXXXX sequences mean

Where \u0041-style sequences in JSON and JS strings come from and what they mean.

ROT13 and the Caesar cipher: simple character substitution

Why shifting by 13 letters makes ROT13 self-inverse, and why anyone still uses it today.

Punycode: how internationalized domains work in DNS

How a domain with non-Latin characters gets converted into an ASCII form with the xn-- prefix.

Morse code: how text becomes dots and dashes

The principle behind encoding letters as dots and dashes, and where Morse code is still used today.

Gzip + Base64: compressing data for text-based transfer

Why compressed binary data also gets Base64-encoded before going into a text field.

XML Entities: escaping characters in XML documents

The five required XML entities without which a document breaks during parsing.