v149 · JavaScript
URL-Safe Base64
Standard base64 uses + and / which must be percent-encoded in URLs. The alphabet: "base64url" option swaps them for - and _. Compare both encodings side by side.
Feature detection: checking…
Input text
URL-unsafe chars (+, /, =)
URL-safe replacements (-, _)
Standard base64
toBase64() — alphabet: "base64"
Result
URL-encoded (percent-encoding applied)
Problem chars
URL-safe base64
toBase64({ alphabet: "base64url" })
Result
URL-encoded (no change needed)
Problem chars
Example URL with token (paste-and-go)
const encoder = new TextEncoder();
const bytes = encoder.encode("user:pass+word/role?admin=true");
// Standard base64 — contains +, /, =
const std = bytes.toBase64();
// → "dXNlcjpwYXNzK3dvcmQvcm9sZT9hZG1pbj10cnVl"
// URL-safe base64 — replaces + → -, / → _, omits = padding
const urlSafe = bytes.toBase64({ alphabet: "base64url" });
// → "dXNlcjpwYXNzK3dvcmQvcm9sZT9hZG1pbj10cnVl"
// (this example has no + or / so looks the same,
// but binary data will differ)
// Decode back
const original = Uint8Array.fromBase64(urlSafe, { alphabet: "base64url" });
see also
- Encode & Decode — base64 round-trip
- Hex Inspector — byte-level view
- Binary File Tools — encode files
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗