Skip to content

URL to Base64

Choose Encode URL String to convert the link itself. Choose Fetch & Encode Resource to convert the file at that link into a data URI. Fetching requires CORS support.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is URL to Base64?

This URL to Base64 converter has two modes. String mode encodes the URL text itself as Base64, which is how some systems pass a redirect address, a callback URL or a link through a parameter or token without escaping problems.

Fetch mode downloads the file the URL points to, such as an image, font or document, and converts its contents into a Base64 data URI, ready to embed in HTML, CSS or JSON. Fetching happens from your browser, so it works with files on servers that allow cross-origin requests (CORS), such as many CDNs and public APIs.

How to use URL to Base64

  1. Choose String to encode the URL text, or Fetch to convert the file at the URL.
  2. Paste the URL.
  3. In String mode, the Base64 appears instantly; in Fetch mode, start the fetch and wait for the file to download.
  4. Copy the Base64 string or data URI.

Key features

  • Encode URL text as Base64
  • Fetch a remote file and convert it to a Base64 data URI
  • UTF-8 support for international URLs
  • Uses the MIME type reported by the server
  • Runs in your browser with no server-side proxy

Common use cases

  • Passing a return or callback URL inside a parameter or token
  • Converting a CDN-hosted image or icon into a data URI
  • Embedding remote assets in single-file HTML
  • Encoding links for systems that reject special characters
  • Testing which servers allow cross-origin downloads

Technical details & standards

String mode encodes the URL as UTF-8 and then standard Base64 (RFC 4648). If the result will itself go into a URL, convert it to Base64URL by replacing + with -, / with _ and removing = padding.

Fetch mode uses the browser's fetch() API and reads the response into a data URI with the MIME type the server reports. The server must send an Access-Control-Allow-Origin header that allows this site; if it does not, the browser blocks the download and you will see an error, in which case download the file and use File to Base64 or the Image to Base64 Converter instead.

Fetch a remote file and convert it to Base64 in code

There is no API behind this page: the conversion runs in your browser. To turn a remote file URL into Base64 on a server or in a script, fetch the bytes and encode them yourself. Each example below produces a data URI that starts data:image/png;base64,iVBORw0KGgo.

JavaScript (Node.js 18+)

const res = await fetch("https://www.codeunpack.com/favicon-16x16.png");
const uri = `data:${res.headers.get("content-type")};base64,` +
  Buffer.from(await res.arrayBuffer()).toString("base64");

Python

import base64, urllib.request

with urllib.request.urlopen("https://www.codeunpack.com/favicon-16x16.png") as res:
    uri = f"data:{res.headers['Content-Type']};base64," + base64.b64encode(res.read()).decode()

curl

curl -s https://www.codeunpack.com/favicon-16x16.png | base64

Frequently asked questions

How do I convert an image URL to Base64?

Use Fetch mode and paste the image URL. If the server allows cross-origin requests, the image is downloaded and converted to a data URI. If it is blocked, download the image and use the Image to Base64 Converter.

Why does fetching a URL fail?

The file's server does not allow cross-origin requests from this site, so the browser blocks the response. This is a browser security rule (CORS) that applies to every web-based tool.

Is Base64 the same as URL encoding?

No. URL encoding (percent-encoding) replaces unsafe characters with %XX codes and keeps the rest readable. Base64 re-encodes the whole value. Use the URL Encoder & Decoder for percent-encoding.

Can I put Base64 inside a URL?

Use the URL-safe variant: replace + with -, / with _ and drop the = padding, or percent-encode the Base64 string. Standard Base64 characters + and / have special meanings in URLs.

Is my data safe?

When you request a URL, your browser sends the request directly to that destination. CodeUnpack does not proxy the request.

Does it work offline?

Once the page has loaded, you can work with local input offline. Loading a URL requires a connection.

More encoders & decoders tools

View all