File to Base64
Drop any file (up to 32 MB) to get its Base64 string or data: URL, plus HTML, CSS, Markdown and JSON snippets. URL-safe option. Encoded in your browser.
Still loading. If the tool doesn’t appear, reload this page.
About this tool
File to Base64
Encode any local file to a Base64 string or data URL in your browser, with HTML, CSS, Markdown and JSON snippets and a URL-safe option.
To convert a file to Base64, drop it here: it is read in your browser and encoded with the RFC 4648 alphabet, every 3 bytes becoming 4 characters. Copy the raw string, a data:<type>;base64,… URL, or a ready HTML, CSS, Markdown or JSON snippet. A 1,024-byte file becomes 1,368 characters — about 33% larger. Nothing is uploaded.
How to use File to Base64
Drag a file into the drop zone or pick one under "Choose a file to encode" — up to 32 MB, read in this tab with the browser File API.
Leave "Include the data: URL prefix" on for a data URL, or turn it off for the raw string — then "URL-safe alphabet (- and _)" and "Keep = padding" shape it. "Wrap at 76 characters" adds MIME line breaks.
Switch the Output tab between Data URL, HTML, CSS, Markdown and JSON, then press Copy output — it always copies the whole string, not just the 4,000-character preview.
Why use File to Base64
Exact size maths
Shows encoded length as 4 x ceil(bytes / 3) and the resulting percentage overhead.
Four paste-ready formats
Emits the data URL plus HTML, CSS, Markdown and JSON snippets around it.
Standard or URL-safe
Switch the raw string between the standard alphabet and the - / _ variant, with or without = padding.
Common use cases
- Inline a 2 KB SVG or favicon into a stylesheet as background-image: url("data:image/svg+xml;base64,…").
- Paste a small PNG into a JSON request body for an API that accepts Base64 image fields.
- Produce a URL-safe Base64 string for a query parameter or filename, where + and / would break.
Frequently asked questions
How much bigger does Base64 make a file?
Exactly 4 characters for every 3 bytes, so about 33.3% larger — a 1,024-byte file becomes 1,368 Base64 characters. Add roughly 20-30 more characters for the data: URL prefix, and more again if you wrap lines at 76 characters.
Link to answerWhat is a data URL and when should I use one?
A data URL is data:<mime>;base64,<payload> (RFC 2397) and embeds the file directly in your markup. Use it for assets under about 10 KB — icons, small fonts, one-pixel images — where saving a round trip beats the 33% size penalty and the loss of separate caching.
Link to answerIs my file uploaded to a server?
No. The file is read into memory in your browser tab with the File API and encoded in JavaScript there. No network request is made, which is why the tool also works offline once the page has loaded.
Link to answerWhat is URL-safe Base64?
It is the RFC 4648 §5 variant that replaces + with - and / with _, so the string can sit inside a URL, a filename or a JWT without escaping. Padding = characters are usually dropped too. Both switches apply to the raw string here; data URLs and snippets stay in standard Base64, because browsers do not decode the URL-safe alphabet inside a data: URL.
Link to answerHow do I convert Base64 back to a file?
Use the companion Base64 to File tool: paste the string or data URL and it decodes the bytes, detects the file type from its signature and saves it with the matching extension.
Link to answerEmbed this tool on your site
Add the File to Base64 widget to your blog or website — free, responsive, no signup. Just keep the “Widget by AltFTool” credit link visible.
<iframe src="https://www.altftool.com/embed/widget/file-to-base64"
title="File to Base64 — free AltFTool widget"
width="100%" height="640" style="border:0;border-radius:12px;overflow:hidden"
loading="lazy" referrerpolicy="no-referrer-when-downgrade" allow="clipboard-write"></iframe>
<p style="font-size:12px;margin:4px 0 0">Widget by <a href="https://www.altftool.com/tools/all/file-to-base64?utm_source=embed&utm_medium=widget" rel="nofollow">AltFTool — free online tools</a></p>