CSS Data URI Converter for Images – Free

Choose an image and this CSS data URI converter returns a complete background-image declaration with the file embedded as Base64. The image stays in your browser.

How to use the CSS Data URI Converter tool

  1. Select the Image file control and choose a PNG, JPEG, GIF or WebP file from your device.
  2. Select Convert. The image is read and encoded on your device.
  3. Read the CSS declaration in the Result box. It starts with background-image: url("data: and ends with a semicolon.
  4. Select Copy and paste the declaration inside a rule in your stylesheet.

What the CSS data URI converter produces

The output is one line of CSS: the background-image property, a url() function in double quotes, and inside it a data URI made of the media type, the marker ;base64 and the encoded file. You can paste it into a rule as it stands.

The media type is taken from the first bytes of the file, not from its name. A GIF saved with a .jpg extension is labeled image/gif. The image bytes are embedded unchanged: the tool does not resize, recompress or strip metadata, so optimize the file before you convert it.

A worked example

The file here is a 2 by 2 pixel PNG of 79 bytes. The tool returned the middle line, 156 characters in total. The selector and braces were added by hand.

.dot {
  background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVR42mP8v4CfgYGBiYGBgYGBAQAVQgGy9omCFwAAAABJRU5ErkJggg==");
}

When inlining an image in CSS pays off

An embedded image arrives with the stylesheet, so the browser makes one request fewer and the picture is available as soon as the CSS is parsed. That suits tiny icons, repeating patterns, placeholders and single-file deliverables.

The costs grow with file size. Base64 adds a third to the bytes. The image can no longer be cached on its own, so every stylesheet change downloads it again. Stylesheets block rendering, so a large embedded photo delays first paint. Build tools that inline assets automatically draw the line at a few kilobytes for these reasons.

Limits and things to check

The converter enforces two limits and leaves a few decisions to you.

  • Files above 20 MiB are refused with Choose a file up to 20 MiB.
  • Other formats, including SVG, BMP and ICO, are refused with Choose a PNG, JPEG, GIF, or WebP file.
  • The result is text only. There is no Download link, so use Copy.
  • A Content Security Policy must allow data: under img-src, or the background will not load.
  • The url(...) part also works in other properties such as list-style-image, mask-image and border-image-source.

Frequently asked questions

Which image formats does the converter accept?

PNG, JPEG, GIF and WebP. The check reads the file signature, so a correctly formatted image is accepted whatever its extension, and a file of another type is rejected even if it is named .png.

Can I convert an SVG to a CSS data URI here?

No, vector files are not accepted. SVG is text, so you can paste its source into the Data URI builder with the media type image/svg+xml and wrap the result in url() yourself.

Does inlining images make a page faster?

Sometimes. It saves a request for small images that are needed immediately. For larger files the extra third in size, the loss of separate caching and the render-blocking stylesheet usually outweigh that saving.

Can I use the output in an img tag?

Yes, with one edit. Copy only the text between the double quotes, beginning with data:image, and use it as the src attribute. The surrounding background-image: url() syntax belongs to CSS.

Is my image uploaded to create the data URI?

No. The file is read with the browser's File API and encoded on your device. The page may fetch its own script when you first select Convert, but no request carries the image.

Related tools