Why URLs need encoding
A URL may only contain a limited set of ASCII characters, and some of those have jobs: / separates path segments, ? starts the query, & and = split parameters, # starts the fragment. To put a space, an accented letter or a literal & inside a value, the character is replaced by % and its UTF-8 bytes in hexadecimal. A space becomes %20, é (two bytes in UTF-8) becomes %C3%A9, and & becomes %26.
Use component scope for a single piece, such as a search term in ?q= or a filename in a path. Use whole URL scope when you have a complete address with unsafe characters inside it and want to keep its structure.
Worked example
The search rock & roll in a query string must be sent as rock%20%26%20roll; left unencoded, the server would see a parameter q=rock and a stray roll parameter. A whole URL https://example.com/café menu.pdf encodes to https://example.com/caf%C3%A9%20menu.pdf.
How this works
Component scope escapes every character except the unreserved set A–Z a–z 0–9 - . _ ~ defined in RFC 3986 §2.3, after encoding the text as UTF-8. It matches JavaScript's encodeURIComponent but also escapes ! ' ( ) *, which RFC 3986 reserves. Whole-URL scope matches encodeURI and leaves the delimiters : / ? # [ ] @ & = + $ , in place. Spaces are written as %20; the + convention only applies to HTML form bodies. Everything runs in this tab.
Frequently asked
Should spaces be %20 or +?
In URLs, %20. The + form is only defined for HTML form submissions (application/x-www-form-urlencoded). Decoders on this site accept both.
What is the difference between the two scopes?
Component escapes everything that has a meaning in URLs, including / ? & =. Whole URL keeps those delimiters so the address still works.
Why is my text encoded twice (%2520)?
The input was already encoded, so its % signs were escaped again. Decode it first.
Which characters are never encoded?
Letters A–Z and a–z, digits 0–9 and the four symbols - . _ ~ (RFC 3986 unreserved characters).
Sources
- RFC 3986 — Uniform Resource Identifier (URI): Generic Syntax
- ECMA-262 — ECMAScript Language Specification
- Wikipedia — Percent-encoding
Reviewed Oct 17, 2026 · test vectors fixtures/dev/url-encode/