URL encode and decode
URL encoding replaces unsafe characters with % and two hex digits of their UTF-8 bytes: a space is %20, & is %26. Encode each value you put into a URL, and decode when you read one back.
Last reviewed 2026-11-04.
Worked examples
| Input | Encoded |
|---|---|
| hello world & more | hello%20world%20%26%20more |
| a/b?c=d | a%2Fb%3Fc%3Dd |
| café ☕ | caf%C3%A9%20%E2%98%95 |
| 100% sure+1 | 100%25%20sure%2B1 |
encodeURI or encodeURIComponent
encodeURIComponentencodes everything except letters, digits and- _ . ! ~ * ' ( ). Use it for a single query value or path segment.encodeURIleaves: / ? # & =alone so a whole URL stays usable.encodeURI("a/b?c=d")is unchanged;encodeURIComponentgivesa%2Fb%3Fc%3Dd.- Non-ASCII text is encoded as UTF-8 bytes:
éis%C3%A9.
Decoding
Switch the tool to Decode. decodeURIComponent("a%20b") gives a b. In form-encoded query strings a + also means a space, but decodeURIComponent does not convert it: decodeURIComponent("a+b") stays a+b. A stray % that is not followed by two hex digits throws a URIError.
Running this on a server
Encoding bugs usually show up in a server that receives the URL. The hosting guide compares small hosts.
Frequently asked questions
Is a space %20 or +?
%20 everywhere. + means a space only in application/x-www-form-urlencoded form data and query strings.
Should I encode the whole URL?
No. Encode each value, then join. Encoding the whole URL also encodes the slashes and colon.
Why double encoding?
Encoding an already encoded string turns % into %25. Encode once, at the point you build the URL.
Sources
- RFC 3986: URI Generic Syntax, percent-encoding checked 2026-11-04
- MDN: encodeURIComponent() checked 2026-11-04