How percent-encoding works
A URL can only carry a limited set of characters safely. Anything outside that set, including spaces, ampersands and accented letters, is replaced by a percent sign followed by the character's byte value in hexadecimal.
Encoding applies that substitution so the text travels intact, and decoding reverses it to recover the original readable string.
- A space becomes %20.
- An ampersand becomes %26 so it is not read as a separator.
When to encode
Encode any value you drop into a URL, especially query-string parameters and search terms, so symbols do not break the link or change its meaning.
- Encode user input, search keywords and parameter values.
- Decode when you want to read or debug an encoded string.
Encoding a value versus a whole URL
This tool uses component encoding, which escapes every reserved character including slashes and question marks. That is correct for a single value but would mangle a complete address.
To build a full URL, encode each piece separately and then join them, rather than encoding the assembled address in one pass.
Common mistakes
Decoding only succeeds on a well-formed string. A stray percent sign that is not followed by two valid hex digits will be rejected as malformed.
Encoding twice produces doubled escapes, so a percent sign turns into %25. Decode an already-encoded value before encoding it again.
Formula
encode: encodeURIComponent; decode: decodeURIComponentFrequently asked questions
- What is the difference from encoding a whole URL?
- This uses encodeURIComponent, which encodes every reserved character. Use it for individual query values, not for an entire URL where slashes should stay intact.

