You can put a picture straight into your HTML or CSS, with no separate image file, by turning it into a Base64 string inside a data: link. The browser reads the picture from the code itself. This is handy for a small logo in a single-file invoice, a tiny icon in a stylesheet, or an HTML page you want to send as one attachment. With the free Base64 Encoder/Decoder it takes about a minute, in your browser, with no upload.
This guide shows the exact steps, the code to paste, and the cases where embedding is the wrong choice.
What a data URL is
A normal image tag points to a file: <img src="logo.png">. A data URL puts the file's contents in the address itself:
<img src="data:image/png;base64,iVBORw0KGgo..." alt="Shop logo">
It has three parts. data: says the content follows, image/png is the type of file, and ;base64, says the rest is Base64 text. Everything after the comma is your picture, rewritten using 64 safe characters.
How to embed an image, step by step
- Prepare the picture. Make it as small as you can first, because Base64 makes it about a third bigger. The Image Compressor shrinks the file size and Resize Image changes its dimensions.
- Open Base64 Encoder/Decoder. Leave Mode on Encode.
- Leave URL-safe (base64url) unticked, which is best for the Result panel too. Wrap lines at 76 chars can stay off. (Copy data URL always uses standard Base64 on one line, so neither setting spoils the copied link.)
- Press Choose file and pick your picture. The left panel now shows its name and size.
- Press Copy data URL in the Result panel. The whole
data:image/...;base64,...text is copied, on one line. - Paste it into your code, as shown below.
Look at the figures under the panels as well. "Input" is your file size, "Output" is the number of characters in the Base64, and "Size change" shows the growth. A 3 KB icon becomes about 4,000 characters. A 300 KB photo becomes around 400,000 characters, which is a very long line in an editor.
The code to paste
In an HTML image tag
<img src="data:image/png;base64,PASTE_HERE" alt="Rahim Stores logo" width="48" height="48">
Replace PASTE_HERE with the data after the comma, or simply paste the whole data URL as the src value. Keep the alt text and set the width and height so the page does not jump while it loads.
In CSS
.logo {
width: 48px;
height: 48px;
background-image: url("data:image/png;base64,PASTE_HERE");
background-size: contain;
background-repeat: no-repeat;
}
Put the whole data URL in quotes inside url().
In an HTML file you will convert to Word
The HTML to Word converter can place only pictures embedded as PNG or JPG data URLs. Pictures that point to a web address are left out, so the steps above are also how you keep a logo in a Word file made from HTML. The complete guide to HTML to Word covers the rest.
Embedding an SVG
For a small SVG file, choose the .svg file in the same way. Your browser reports its type as image/svg+xml, so Copy data URL gives a link that starts data:image/svg+xml;base64,.
You can also encode SVG as text. Paste this into "Plain text (UTF-8)":
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><circle cx="12" cy="12" r="10" fill="#1a73e8"/></svg>
The Result panel gives:
PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCI+PGNpcmNsZSBjeD0iMTIiIGN5PSIxMiIgcj0iMTAiIGZpbGw9IiMxYTczZTgiLz48L3N2Zz4=
Because this route starts from text, there is no Copy data URL button. Copy the Result and add the start yourself: data:image/svg+xml;base64, followed by the text.
How to check that it worked
Open the page in a browser. If the picture shows, you are done. If not, paste the entire data URL into the encoder after switching Mode to Decode. The tool removes the data:...;base64, start, and if it says "This decodes to binary data" with a size and a hex preview, then the Base64 itself is fine and the problem is in the surrounding code. Press Download decoded file to confirm it is the right image. The file is saved with the type the data URL names (for example .png), so it opens directly.
If instead you see "The input contains characters that aren't valid Base64." or "The Base64 input has an invalid length.", the paste was damaged or cut off. Copy it again.
When embedding is a good idea
- Tiny icons, around a few kilobytes, that are used once.
- A logo in an HTML invoice or report you send as a single file.
- A page that must work offline with nothing else beside it.
- A stylesheet that must be self-contained, such as a component you hand to someone else.
When it is a bad idea
- Large photos. The code grows by about a third, and it has to be downloaded before the page can show anything below it.
- The same image on many pages. A separate file is downloaded once and then reused from the cache. An embedded copy is downloaded again with every page.
- Images you will change often. You have to re-encode and paste again each time.
- Email newsletters. Some email programs block embedded data. Test before you rely on it.
- Pages that need to be easy to read. One enormous line in the middle of your source file makes it difficult to edit.
A fair rule is to embed only what is small and used once, and to link everything else as a normal file.
Common mistakes
The image type does not match
If the file type is unknown to your browser, Copy data URL uses application/octet-stream, which is a general "binary file" label, and some browsers will not draw it as an image. Edit the part before ;base64 to the right type: image/png, image/jpeg, image/webp or image/svg+xml.
URL-safe was ticked
With URL-safe on, the Result panel uses - and _ and no = padding. That form is for URLs and tokens, and a data URL built by hand from it will generally not display. The Copy data URL button is not affected, because it always builds the link from standard Base64. If you copied from the Result panel by hand, untick URL-safe and copy again.
The line was broken when pasted
A data URL should be one unbroken line. Copy data URL gives you that. If you copied by hand from the Result panel with Wrap lines at 76 chars on, you will have line breaks inside the value. Use the button, or turn the wrapping off.
The picture is blurry or pixelated
Embedding does not change quality. If it looks blurry, the file was too small to begin with, or the width and height in your tag are larger than the picture's real size.
Related tools
- Base64 Encoder/Decoder: the tool used in this guide. Its complete guide lists every option.
- Image Compressor: reduce the size before you encode.
- Resize Image: make the picture the exact size you will show it.
- HTML to Word: turn the finished HTML into a Word file.
Quick checklist
- Make the picture small first.
- Use Copy data URL (it always uses standard Base64); with a hand copy, URL-safe off.
- Paste the whole
data:text intosrcorurl("..."). - Embed only small images that are used once.
- Decode the data URL again if you need to prove it is correct.



