Ready to try it? Use our free Image to Base64 tool.
Convert Image URL to Base64: Free Online Tool (No Code Needed)
Quick answer: To convert image url to base64, paste the link into a free online converter like ToolFlexy’s Image to Base64 tool, which fetches an accessible image in your browser and returns a Base64 string, Data URI, or ready-to-use HTML/CSS snippet — no download, sign-up, or code required.
Learning how to convert image url to base64 is useful any time you need to embed a picture directly in HTML, paste it into a CSS file, or drop it into a JSON payload. The fastest way is a free online converter that fetches the image and encodes it for you. No account, no software, and no code required.
ToolFlexy’s Image to Base64 tool does exactly this: paste a link, and it fetches and encodes the image right in your browser. Below is exactly how to convert image to Base64 from a URL, why some links won’t convert (including cross-origin restrictions and file limits), and a quick code snippet if you’d rather handle it yourself.
What Does It Mean to Convert Image URL to Base64?
Base64 is a way of representing binary data — like an image file — as plain text. When you convert image url to base64, a tool downloads the image at that link and re-encodes its raw bytes into a long string made of letters, numbers, and a few symbols.
That string can then be pasted anywhere plain text is accepted: directly into an HTML <img> tag, a CSS background-image rule, a JSON payload, or an email template, without linking to an external file at all. The image effectively becomes part of the document itself, rather than a separate resource the browser has to fetch.
This is different from simply linking to an image URL. A normal <img src="https://example.com/photo.jpg"> tag still depends on that external file existing and being reachable every time the page loads. A Base64-encoded image doesn’t — once you’ve converted the image URL to Base64 and pasted the resulting string into your code, the image data travels with the document itself.
How to Convert Image URL to Base64 Online (Free)
Here’s the fastest way to convert image url to base64 without writing any code:
- Open the Image to Base64 tool. It runs entirely in your browser — nothing you convert is uploaded to a server.
- Find the “Import from the Web” box and paste your image’s direct URL into the “Have an image link?” field.
- Click “Fetch & Convert.” The tool downloads the image and encodes it instantly, right there in the page.
- Pick your output format. Choose Raw Base64, Data URI, HTML, CSS, JSON, XML, a JS variable, or a Favicon tag, depending on where the code is headed.
- Copy the result with one click, or download it as a .txt file to use later.
No sign-up, no vague limits (there’s a clearly stated 15MB file size cap), and no watermark on the output. If you’d rather start from a file already saved on your device instead of a link, the same tool also accepts drag-and-drop uploads and clipboard paste — the URL method is just the fastest way to convert image url to base64 when you already have a link and don’t want to download it first.

Choosing the Right Output Format
Once you convert image url to base64, you’ll need to pick a format that matches where the code is going. Here’s what each option is actually for:
- Raw Base64 — just the encoded string, no prefix. Useful when a system expects the data on its own, such as an API field that already knows the content is an image.
- Data URI — the Base64 string with a
data:image/png;base64,prefix attached. This is what you need for thesrcattribute of an<img>tag or a CSSurl()value, since the prefix tells the browser how to interpret the text that follows. - HTML — a ready-made
<img>tag with the Data URI already inserted, so you can paste it straight into a page. - CSS — a
background-imagerule, pre-formatted for a stylesheet. - JSON — the encoded image wrapped as a field in a JSON object, for sending through an API.
- XML, JS Variable, or Favicon tag — the same underlying Base64 data, reformatted for whichever one of those three contexts you’re working in.
Getting the format right the first time avoids a common mistake: pasting raw Base64 (with no prefix) directly into an <img src> attribute and getting a broken image, when what that attribute actually needed was the Data URI version with the data:image/...;base64, prefix included.
Why Some Image URLs Won’t Convert (The CORS Issue Nobody Explains)
Occasionally, when you try to convert image url to base64, pasting the link and clicking convert returns an error instead of a result. One possible cause is CORS (Cross-Origin Resource Sharing). Other causes include a broken link, a sign-in requirement, an unsupported image or a file above the size limit.
Here’s what’s actually happening. A real browser-based converter fetches the image using your own browser, not a hidden server somewhere. That request has to follow the same cross-origin rules (CORS) any webpage does. If the image’s own server doesn’t explicitly allow outside sites to fetch it, your browser blocks the request before the tool ever sees the image data — and there’s no workaround from the browser side, by design.
It’s the same protection that stops a random website from silently reading data off another site you’re logged into. Without it, any page you visit could quietly pull private content from your bank’s site or your email in the background. CORS exists specifically to prevent that, and it applies just as strictly to a harmless image fetch as it does to anything else.
This is also a useful way to evaluate any tool that claims to always be able to base64 encode an image url, no matter the source. A tool that routes your image through its own server to dodge CORS can technically get around the restriction, but it means the image is no longer staying private in your browser. It passes through someone else’s infrastructure first, which runs against the entire point of a “nothing uploaded” tool.
If you hit this error, two options to try:
- Download the image first, then upload the file directly instead of pasting the URL. This avoids the cross-origin fetch, but the file must still be a supported, readable image within the tool’s 15 MB limit.
- Use an image hosted somewhere that explicitly allows cross-origin access, such as a CDN or a storage bucket configured for public access.
How to Base64 Encode an Image URL in JavaScript
If you’re building this into your own app instead of using a tool, here’s the core pattern for how to base64 encode an image url using the Fetch API:
async function imageUrlToBase64(url) {
const response = await fetch(url);
if (!response.ok) throw new Error("Image request failed: " + response.status);
const blob = await response.blob();
if (!blob.type.startsWith("image/")) throw new Error("Response is not an image");
if (blob.size > 15 * 1024 * 1024) throw new Error("Image exceeds 15 MB");
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result); // includes the data: prefix
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}The same CORS rule from above applies here too. This snippet throws an error for any image URL whose server doesn’t send the right CORS headers, regardless of how clean the code is. That isn’t something you can fix in JavaScript; it has to be allowed on the image’s server side, which is outside your control as the person requesting the image.
If you’re working server-side instead (Node.js, Python, or similar), CORS doesn’t apply at all, since the restriction is enforced by browsers, not servers. A backend script can fetch nearly any public image URL and encode it as Base64 directly, which is why server-side code is often the more reliable choice when you need to encode image urls at scale rather than one at a time.
Where to Use a Base64-Encoded Image
Once you convert image url to base64, the resulting string is most useful in a handful of specific situations, rather than as a general replacement for normal image links:
- Small icons and logos in CSS or HTML — embedding avoids a separate HTTP request for a tiny file, which can genuinely speed up a page with many small graphics.
- Email templates — test Data URI support in the email clients you target. Some clients block Base64 images; hosted images or CID attachments may be more suitable.
- JSON APIs or config files — where an image needs to travel as part of a text payload instead of as a separate attachment.
- Quick prototypes — pasting a Base64 string into an
<img>tag to test something without hosting a file anywhere first.
One tradeoff is worth knowing before you convert an image to Base64 for production use: the resulting text is roughly 33% larger than the original image file. For a small icon, that’s negligible. For anything bigger, that overhead adds up fast, which is why it’s worth compressing an image or resizing it before encoding, rather than converting a large photo as-is.
If your source image is in a format like HEIC or TIFF, converting it to something web-friendly first with a tool like HEIC to JPG or the Image Resizer keeps the final Base64 string smaller too, since those formats tend to produce bulkier output than a well-compressed JPG or WEBP.
Common Mistakes When You Convert Image URL to Base64
Most people who try to base64 encode image url data run into one of the same handful of issues. A few small mistakes account for most of the confusion:
- Forgetting the
data:prefix when pasting a Data URI into an<img src>attribute — without it, the browser has no way to know the string is image data rather than plain text. - Converting a large, uncompressed photo instead of a small icon, which produces a Base64 string that’s awkward to work with and slows down whatever file it’s pasted into.
- Assuming a failed conversion means the tool is broken, when it’s usually the CORS restriction described above, tied to the source server rather than the converter.
- Using Base64 for every image on a page instead of just small, repeated assets — for large or unique images, a normal linked file (with caching) is almost always faster to load.
Image URL Import or Base64 Encode Decode: Which Should You Use?
Use Image to Base64 when you have a direct image link and want Fetch & Convert, an image preview, or prepared HTML/CSS output. Its file limit is 15 MB. URL import contacts the original image host, which can see that request; encoding happens in your browser without a ToolFlexy conversion-server upload.
Use the updated Base64 Encode Decode converter for text, local binary files up to 20 MB, or an existing Base64 string. To create an image Data URI there, choose Encode, select the saved image with Choose File, enable Output Data URI and click Encode. It does not fetch an image from an ordinary web address: pasting a URL in Encode converts the URL’s text, not the image behind it.
To recover a file, choose Decode and paste its Base64 or Base64 Data URI, then Download. A binary hex preview is expected for bytes that are not readable text. Copy copies the preview; Download preserves the decoded bytes. Standard and URL-safe alphabets are detected automatically. For normal text, match UTF-8, Latin-1 or the appropriate UTF-16 byte order to the source.
Check a Small Example Before Converting a File
In the text converter, Hello becomes SGVsbG8=. Decode that value to get Hello back. This checks the direction without needing a large image. For a real image, keep its original file and compare the decoded download. A correct Base64 round trip preserves bytes; it does not guarantee that the source image is valid or appropriate for every browser, email client or application.
Conclusion
When you need to convert image url to base64, it comes down to one real choice: use a free browser-based tool for a quick, one-off conversion, or write a few lines of code if you’re automating it inside an app. Either way, CORS is one important constraint, alongside link access, supported formats, file size and device resources.
Try the Image to Base64 converter now. Paste a link to convert image url to base64 instantly, or upload a file, and get your Base64 string, Data URI, or HTML tag in seconds.



