How to use the image to Base64 converter
- Choose an image or drop it on the box: PNG, JPEG, WebP, GIF, AVIF or SVG, up to 8 MB.
- Check the preview, file size and dimensions.
- Write alt text that describes the image (it’s used in the HTML and Markdown snippets).
- Pick the output: data URI, CSS background, HTML
<img>or Markdown. - For SVG files, choose URL-encoded (smaller) or Base64.
- Copy the snippet into your code.
Use a sample image loads a small generated picture, so you can see each output format before choosing your own image.
How data URIs work
A data URI packs a file into a URL: data: + the media type + ;base64, + the encoded bytes, for example data:image/png;base64,iVBORw0KGgo…. Browsers decode it in place, so the image appears without a request to the server. The file is read with the browser’s FileReader API. No upload happens, so it works offline and with private images.
The snippets add what each context needs:
- CSS:
background-image: url("…")withbackground-size: containand the image’s width and height. - HTML:
<img>withwidthandheightattributes, which reserve space and prevent layout shift, plus your alt text. - Markdown:
, supported by most Markdown renderers.
Worked examples
Example 1: a tiny icon in CSS
A 16 × 16 PNG icon of 300 bytes becomes a data URI of about 420 characters. The check is green: inlining saves a request and costs almost nothing. Paste the CSS snippet into your stylesheet.
Example 2: an SVG logo
Choose an SVG logo of 2 KB. URL-encoded, the data URI is around 2.2 KB, whereas Base64 would be about 2.7 KB. For logos used on every page, a separate cached file is still usually the better choice.
Example 3: a photo (don’t inline it)
A 180 KB JPEG becomes about 240 KB of text. The check turns red. Inlining it would delay rendering of the whole HTML or CSS file. Serve it as a normal image with loading="lazy" instead.
Performance guidance
- Under 4 KB: inline freely.
- 4–20 KB: inline only if the image is critical and always visible immediately.
- Over 20 KB: use a normal file, optimised (WebP or AVIF) and cached.
Remember that data URIs in CSS are downloaded even if the rule never applies, and they’re re-downloaded whenever the stylesheet changes.
Common mistakes
- Inlining large images, which makes HTML and CSS slower to load and parse.
- Missing dimensions, which causes layout shift when the image renders.
- No alt text on meaningful images.
- Base64-encoding SVGs when URL-encoding would be smaller.