Binary files, graphic assets, and authorization tokens often need to be transmitted across channels designed solely for plain ASCII text. Converting raw 8-bit octets into 6-bit Base64 representations enables inlining assets directly into CSS rules, HTML tags, and API JSON payloads.
The Base64 & Data URI Converter provides instant, client-side encoding and decoding for both UTF-8 text strings and binary image files.
1. Standard Base64 vs. RFC 4648 URL-Safe Base64
Standard Base64 encoding utilizes 64 printable ASCII characters (A-Z, a-z, 0-9, +, /), using = for byte padding. However, the characters +, /, and = possess reserved semantic meanings in URL query parameters and path segments.
┌─────────────────────────────────────────────────────────────┐
│ Character Set Comparison: │
│ • Standard Base64: A-Z, a-z, 0-9, + and / (pad =)│
│ • URL-Safe Base64: A-Z, a-z, 0-9, - and _ (no pad)│
└─────────────────────────────────────────────────────────────┘
Conversion Mapping:
- Replace
+with hyphen-. - Replace
/with underscore_. - Strip trailing padding
=characters (optional based on consumer parser requirements).
// URL-safe base64 conversion
export function toBase64Url(base64: string): string {
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}
NOTE: URL-safe Base64 is the required encoding standard for JWT signatures, OAuth 2.0 PKCE code verifiers, and modern web authentication credentials.
2. Inlining Binary Media via Data URIs
A Data URI embeds raw file content directly into web documents using the standard URI scheme:
data:[<mediatype>][;base64],<data>
Common Production Examples:
- Inlining SVG Icons:
TERMINAL // CODE
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg=='); - Inlining 1x1 Transparent PNG Spacer:
TERMINAL // CODE
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=" alt="" />
3. Step-by-Step Tool Guide
[ Step 1: Input Text or File ] ──▶ [ Step 2: Choose Encode / Decode ] ──▶ [ Step 3: Copy Format Output ]
- Enter UTF-8 text or drop any local file (
PNG,SVG,PDF,JSON) into the ingestion dropzone. - Select target mode: Standard Base64, URL-Safe Base64, or Data URI.
- Inspect generated file size metrics and byte inflation ratio (~33% expansion).
- Click Copy Result to copy the encoded string to your clipboard.