b2KIT

Image to Data URL

Convert images to complete data URL format for direct HTML/CSS embedding.

Tested tool guide Tested browser tools Checked August 16, 2026

What Image to Data URL does, with a checked example

Image to Data URL turns the exact bytes of a selected image into a complete data: URL that can be placed in an HTML attribute or CSS url() value. It Base64-encodes the file and adds the image media type plus the data URL prefix, so the result is more than a bare Base64 string. The common surprise is size: Base64 expands binary data by roughly one third before the prefix is added. The conversion changes representation, not image dimensions, pixels, quality, or file format.

Worked example

A concrete input and expected output from the current implementation.

Input

Upload pixel.gif as image/gif, containing exactly these 34 bytes in hexadecimal: 47 49 46 38 39 61 01 00 01 00 80 00 00 00 00 00 FF FF FF 2C 00 00 00 00 01 00 01 00 00 02 01 4C 00 3B

Expected output

data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==

Those 34 GIF bytes encode to the 48-character Base64 payload shown. Adding the image/gif media type and ;base64 marker produces the complete data URL.

How the result is produced

1

Anatomy of the result

A Base64 image data URL has the form data:<media-type>;base64,<payload>. For a GIF, the prefix is data:image/gif;base64,. Everything after the comma encodes the original file bytes as ASCII characters. Trailing equals signs are Base64 padding and belong to the payload. The entire string, including the prefix and comma, is the usable URL.

2

Byte-for-byte representation

The generated string represents the stored image file, including its existing compression and metadata, rather than a new description of its pixels. Decoding the Base64 portion recovers the original bytes when the media-type prefix is excluded. Since data URL conversion does not reduce the source file, a large PNG or JPEG produces an even larger text value.

Good uses

  • Embed a small icon directly in an HTML img src attribute without managing a separate image file.
  • Place a small background image inside a CSS url() value for a self-contained stylesheet or component.
  • Create a complete image string for JSON, configuration, or source code whose consumer explicitly accepts data URLs.

Limits and checks

  • Base64 increases the stored size by about one third, excluding the data URL prefix. Large images can make HTML, CSS, or configuration files unwieldy.
  • Confirm that the image media type in the prefix matches the actual file format. A valid payload paired with the wrong image/... label may not render correctly.
  • A data URL is embedded image data, not a public hosted address. Content Security Policy can also block data: images unless the relevant directive permits them.

Common questions

Can I use the result directly in both HTML and CSS?

Yes. A complete result can be assigned to an img element's src attribute or placed inside CSS url(), provided that context accepts data URLs. Quote it as required by the surrounding HTML or CSS. For large images, a normal file URL is usually easier to maintain, and a site's Content Security Policy may disallow data: images.

Does conversion change the image or upload it?

No. Encoding the file as a data URL does not resize, redraw, or recompress its pixels. This tool performs the conversion entirely in the browser, so the selected image is not uploaded. The resulting string still contains the complete image data, however, so anyone who can read that string can recover and view the image.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools