Eskillsfy

Home / Blog / Images

Images · 23 Nov 2026

Image to Base64: how it works and how to build one

Convert an image to a Base64 data URI, <img> tag or CSS. This guide explains what happens behind the button and shows the code, so you can build your own.

What it does

Embed small icons and images directly in HTML, CSS, JSON or emails. Get a raw Base64 string, a data URI, a ready <img> tag, a CSS background rule or Markdown.

When to use it

  • Inline icons in CSS or HTML emails
  • Embedding images in JSON
  • Quick tests without hosting

How to use it

  1. Choose or drop an image.
  2. Pick the output format.
  3. Copy the result.

Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/image-to-base64

How it works

FileReader.readAsDataURL reads a file and returns a data: URI: ‘data:’, the MIME type, ‘;base64,’ and the Base64 of the bytes. That string can go straight into an <img src> or a CSS url().

Base64 makes files about 33% bigger and can’t be cached separately, so it suits only small images like icons.

Build it yourself

Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.

dataUri.ts (ts)

export const toDataUri = (file: File) =>
  new Promise<string>((resolve, reject) => {
    const r = new FileReader();
    r.onload = () => resolve(r.result as string);
    r.onerror = () => reject(r.error);
    r.readAsDataURL(file);
  });

// <img src={await toDataUri(file)}>   or   background-image: url("data:image/png;base64,...")

Make it production-ready

  • Offer CSS, HTML and Markdown snippets ready to paste.
  • Warn when the image is larger than ~10 KB.

Questions

When should I inline an image?

For small icons under about 10 KB. Larger images are better as normal files so browsers can cache them.

Try the Image to Base64

Free, runs in your browser, nothing is uploaded.

Open it
Keep reading

More in Images

All posts