PDFVela — pdfvela.com

How do I embed an image in HTML or CSS with Base64?

One file instead of two — when a data URI is the right choice, and how to use it without slowing your page down

By · Updated November 10, 2026

What a data URI is

Normally an HTML page points to a separate image file, and the browser fetches it with a second request. A data URI puts the image itself into the page as text. It starts with a short label that says what kind of file it is, followed by the file written in Base64:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA…

Everywhere a browser accepts an image address — an img src, a CSS url(), a favicon link — it also accepts a data URI.

1. Turn the image into Base64

Open Image to Base64, choose your picture (JPG, PNG, WebP, GIF, SVG, ICO, BMP or AVIF) and pick the format you need:

You want to…Choose
Put the image in an HTML pageHTML img tag
Use it as a background in a stylesheetCSS rule
Paste it into JSON, Markdown or a form fieldData URI
Send it to an API that asks for the bare codeBase64 code only

Click Convert, then Copy. For long results, downloading the .txt file is safer — it is easy to miss the end of a very long line when selecting by hand.

2. Paste it where you need it

In HTML, the img tag from the tool goes straight into the page. Add a meaningful alt text between the quotes so screen readers can describe the image.

In CSS, paste the rule into the selector you want, for example a button or a header. Remember to give the element a size, since a background image does not size the element by itself.

In JSON or an API request, paste the data URI (or the bare code, if the documentation asks for it) as a string value. Check the service's size limit first; many APIs reject requests over a few megabytes.

3. Keep embedded images small

Base64 text is about 33 % bigger than the original file, and it is downloaded again every time the page or stylesheet changes. A practical rule:

  • Under 10 KB — icons, small logos, simple shapes: embedding is a good idea.
  • 10–100 KB — acceptable in single-file documents, offline pages and email templates.
  • Over 100 KB — keep it as a normal image file on a web page.

To make an image smaller before converting, use Compress PNG or Compress JPG, or lower its pixel size with Resize image. A 2000-pixel-wide photo shown 300 pixels wide is wasting most of its size.

Common mistakes

  • Cutting the text short. A missing character at the end breaks the whole image. Copy with the button or download the .txt file.
  • Wrong type in the label. A JPG labelled image/png may still display in some browsers but fail in others. The converter reads the real type from the file, so its label is always right.
  • Line breaks inside the code. Some editors wrap long lines and insert breaks. In HTML and CSS the data URI must stay on one line.
  • Huge images in CSS. Every page that uses the stylesheet downloads the image, even if it never shows it. Keep big pictures as files.

When not to use Base64

Use normal image files for photos, for anything over about 100 KB, for images you want to appear in search results and for images that are used on many pages (a file is cached once; embedded text is repeated). Base64 is a tool for small, self-contained pieces — not a replacement for image files.

Ready to try it? It is free and your file stays on your device.

Open Image to Base64

Embedding images with Base64 — common questions

Does a Base64 image load faster than a normal image file?

Only for very small images. It saves one network request, but the text is about a third bigger than the file and cannot be cached on its own. For icons of a few kilobytes it is a win; for photos it usually makes the page slower.

Will search engines see a Base64 image?

A data URI image has no address of its own, so it cannot appear in image search results. Keep the photos you want found as normal files and use Base64 for decoration, icons and logos.

Why does my image show in the browser but not in my email?

Many email apps block or remove data URIs for security reasons. For email, a hosted image or an attachment referenced by the email itself is more reliable. Always send yourself a test first.

Can I embed an SVG without Base64?

Yes. In HTML you can paste the svg code directly into the page. In CSS you can use a URL-encoded SVG instead of Base64, which is often a little shorter. Base64 is the simplest option that always works.

Is my image uploaded when I convert it?

No. The Image to Base64 tool reads the file in your browser and writes the text on your own device; nothing is sent to a server.