Skip to content
CornerTools

Image to Base64

Turn an image into a Base64 data URI, an HTML <img> tag or a CSS background, with a preview — on your device.

Mode
Characters: 0

Turns an image into a Base64 data URI, the image written as text, so it can sit inside an HTML page, a CSS file or a JSON field instead of being a separate file. It also writes the <img> tag, with the image's width and height, and the CSS background-image declaration, ready to paste. The image is encoded in your browser and never uploaded.

How to use it

Drop an image on the box, paste a copied screenshot or image anywhere on the page, or open one with Open file. Output as sets the form:

  • Data URI (the default): data:, the image's type, then its Base64. It goes wherever a URL to an image goes.
  • HTML: an <img> tag with the data URI as its source and the image's size, so the page does not jump as it loads. Its alt is left empty, for a description of the image to go in.
  • CSS: a background-image declaration, for a style rule.
  • Base64: the bare Base64, for a JSON field or an API that takes the type separately. It alone takes URL-safe, padding and line-wrap options, those of the Base64 Encoder & Decoder.

HTML and CSS appear once the browser has shown the image, which the preview under the result does, with its size in pixels and type. Copy takes the whole result, and Download saves it as a text file. Files up to 50 MB are taken; the footer says how much larger the text is than the file. Any other file, or typed text, still encodes as a data URI.

Examples

A small SVG icon

Image (icon.svg)
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#16a34a"/><path d="m7 12 3 3 7-7" stroke="#fff" stroke-width="2" fill="none"/></svg>
Data URI
data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIxMCIgZmlsbD0iIzE2YTM0YSIvPjxwYXRoIGQ9Im03IDEyIDMgMyA3LTciIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBmaWxsPSJub25lIi8+PC9zdmc+
HTML
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIxMCIgZmlsbD0iIzE2YTM0YSIvPjxwYXRoIGQ9Im03IDEyIDMgMyA3LTciIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBmaWxsPSJub25lIi8+PC9zdmc+" width="24" height="24" alt="">
CSS
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIxMCIgZmlsbD0iIzE2YTM0YSIvPjxwYXRoIGQ9Im03IDEyIDMgMyA3LTciIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIyIiBmaWxsPSJub25lIi8+PC9zdmc+");

The 204-byte file becomes 298 characters of data URI. The tag carries the 24 × 24 size the browser drew the icon at.

Frequently asked questions

For small images, such as icons and tiny backgrounds of a few kilobytes: the page saves a request for each. For anything larger it costs more than it saves. The text is a third larger than the file, it is downloaded again with every page or style sheet that holds it instead of being cached once, and the page cannot show until it has arrived. Email is the other common use, where linked images are often blocked; many email apps block data URIs too, so test before sending.
Base64 writes every 3 bytes as 4 characters from a set of 64 safe ones, so the text is 4/3 the size of the file, plus the short data: prefix. Compress the image first with the Image Compressor to keep it small.
Yes: the file is encoded byte for byte, never re-saved, so an animated GIF stays animated and a photo keeps its camera details and location. A compressed SVG (.svgz) is the one file unzipped first, as a data URI cannot say its bytes are compressed; the Base64 form keeps the file as it is. The tool warns when a photo carries a GPS position; remove it first with Remove EXIF Data.
They encode, with the type image/heic, but most browsers cannot show them, so the result would not display on a web page. Convert them first with HEIC to JPG.
Choose Decode and paste the Base64 or data URI: the image is shown and can be downloaded.

See also