URL Encoder & Decoder→Specialized Version
πŸ”—

URL Encoder

Encode for URLs

Tip: Use encodeURIComponent for query parameter values. Use encodeURI only for full URLs where you want to preserve : / ? & characters.
Common URL Encodings Reference
␣→%20
!β†’%21
"β†’%22
#β†’%23
$β†’%24
&β†’%26
'β†’%27
+β†’%2B
,β†’%2C
/β†’%2F
:β†’%3A
?β†’%3F
@β†’%40
=β†’%3D

URL Encoder

Convert text with special characters into a URL-safe format. Percent-encoding replaces unsafe characters with %XX codes.

Why URL Encoding Is Necessary

CharacterIssueEncoded
(space)Terminates URLs%20 or +
&Separates parameters%26
=Separates key/value%3D
?Starts query string%3F
#Starts fragment%23

URL Encode Implementation

``javascript // Encode for query parameters (most common) function urlEncode(text) { return encodeURIComponent(text); }

// Encode full URL (preserves URL structure) function urlEncodeFull(url) { return encodeURI(url); }

// Encode with + for spaces (form encoding) function urlEncodeFormData(text) { return encodeURIComponent(text).replace(/%20/g, '+'); }

// Examples urlEncode('Hello World!'); // "Hello%20World%21" urlEncode('price=100&qty=2'); // "price%3D100%26qty%3D2" `

Building Encoded URLs

`javascript function buildUrl(base, params) { const searchParams = new URLSearchParams(); for (const [key, value] of Object.entries(params)) { searchParams.append(key, value); } return ${base}?${searchParams.toString()}; } `

Use this encoder to safely include any text in URLs.

What Percent-Encoding Escapes

Percent-encoding replaces a byte with % followed by its two hex digits. Which bytes need escaping depends on where in the URL they appear, which is why JavaScript ships two different functions.

CharacterEncodedWhy
space%20 (or + in a form body)Terminates the URL in some parsers
&%26Separates query parameters
=%3DSeparates key from value
?%3FStarts the query string
#%23Starts the fragment
/%2FPath separator
+%2BMeans a space in form encoding
Γ©%C3%A9Two UTF-8 bytes
`javascript encodeURI('https://ex.com/a b?x=1&y=2'); // 'https://ex.com/a%20b?x=1&y=2' β€” structure preserved

encodeURIComponent('a b?x=1&y=2'); // 'a%20b%3Fx%3D1%26y%3D2' β€” everything escaped `

Use encodeURI on a whole URL and encodeURIComponent on each value you insert into one. Getting this backwards is the single most common URL bug: encodeURI on a query value leaves & intact, and a value containing & then splits into two parameters.

Better still, let the platform build it:

`javascript const url = new URL('https://example.com/search'); url.searchParams.set('q', 'a b & c'); // escaping handled `

Encoding Is Not Encryption

Base64 and percent-encoding both make data safe to *transport*. Neither makes it secret β€” both are trivially reversible by design, with no key involved. A Base64 string in a URL, a cookie or a header is readable by anyone who sees it.

PurposeUse
Safe transport of binary over textBase64
Safe transport of text in a URLPercent-encoding
ConfidentialityAES-GCM, TLS
IntegrityHMAC, a digital signature
Password storagebcrypt, scrypt, Argon2

Size Costs

Base64 expands data by exactly 4/3 β€” three bytes become four characters β€” plus padding. A 100 KB image becomes about 133 KB as a data URI, and it cannot be cached separately from the document that carries it. Inline small icons; link everything else.

Percent-encoding expands unpredictably: an ASCII character that needs escaping becomes three characters, and a non-ASCII character becomes three per UTF-8 byte. Γ© is %C3%A9 β€” six characters for one letter.

UTF-8 Is the Only Sane Default

Every encoding decision on the modern web assumes UTF-8. Where it goes wrong:

  • btoa throws on non-Latin-1 input. Encode to UTF-8 bytes first:
btoa(String.fromCharCode(...new TextEncoder().encode(text))).
  • atob returns Latin-1. Decode back with new TextDecoder().decode(bytes).
  • A BOM breaks parsers. Excel writes one at the start of CSV exports; strip it before
parsing.
  • Length is ambiguous. "πŸ‘¨β€πŸ‘©β€πŸ‘§".length is 8 in JavaScript, 1 to a reader. Use
Intl.Segmenter` when the count is shown to a person.

Frequently Asked Questions

Why encode URLs when working with URL Encoder?

URL encoding ensures special characters don't break URL parsing. Without encoding, spaces terminate URLs, & starts new parameters, and = separates keys from values. Encoding also handles unicode characters.

Should I use encodeURI or encodeURIComponent?

Use encodeURIComponent for values (query parameters). It encodes all special characters. Use encodeURI only for complete URLs where you want to preserve structure. For most cases, encodeURIComponent is correct.

Why do spaces sometimes become + and sometimes %20?

Both are valid. %20 is standard percent-encoding. + is from HTML form encoding. Most servers accept both in query strings. encodeURIComponent produces %20; replace with + if needed.

Related Tools

Explore other tools you might find useful:

More URL Encoder & Decoder tools

You might also need