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.
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. Itsaltis left empty, for a description of the image to go in. - CSS: a
background-imagedeclaration, 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
data: prefix. Compress the image first with the Image Compressor to keep it small.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.See also
- Base64 Encoder & Decoder — for text and any other file, both ways.
- Image Compressor — to make the image smaller before inlining it.
- Remove EXIF Data — to remove a photo's location before encoding it.
- SVG to PNG — to turn an SVG into a PNG where a data URI must be a raster image.