When to use it
- One self-contained HTML file: logos in email signatures, HTML reports viewed offline, or internal pages where you cannot host image files
- Small icons inside CSS: check marks, arrows and background patterns without an extra request
- Images in APIs and JSON: testing an API that takes Base64 images, or putting a small picture in a config file
- Markdown with the pictures inside: sharing a single document instead of a folder of images
What the text file contains
With the default option, logo-base64.txt holds three blocks:
| Block | Looks like | Paste it into |
|---|---|---|
| Data URI | data:image/png;base64,iVBOR... |
Anywhere an image address goes |
| HTML | <img src="data:..." width="32" height="32" alt=""> |
HTML, or the HTML mode of an email signature editor |
| CSS | .image { background-image: url("data:..."); } |
A stylesheet or style tag |
The HTML and CSS include the picture’s width and height in pixels so the page can reserve its space. SVG sets its own size, so it is written without one. Rename .image and fill in alt="" to suit your page.
Mind the size
Base64 writes every 3 bytes as 4 characters, so the text is about 33% larger than the file.
| Original image | Base64 length | Good fit? |
|---|---|---|
| 2 KB icon | about 2,700 characters | Great |
| 20 KB logo | about 27,000 characters | Fine |
| 200 KB photo | about 270,000 characters | Better as a file |
| 2 MB photo | about 2.7 million characters | May freeze editors |
A picture in a data URI cannot be cached on its own, so it is read again on every page that contains it. If the same image appears on many pages, a normal file is faster. Shrink large pictures first with Compress image or Resize image.
Tools that go well with it
- Turn an SVG icon into PNG first with SVG to PNG
- Make a browser tab icon with the Favicon generator
- Tidy the JSON you are pasting the Base64 into with the JSON formatter
What is a TXT file?
A TXT file contains plain text only: no fonts, layout, images or hidden markup. That makes it the most portable document format there is. It opens on every device and in every text editor, is easy to search and process with scripts, and takes up very little space.
The trade-off is that formatting such as bold text, tables and pictures cannot be stored. Line breaks and blank lines are the only structure a TXT file has.