URL Encoder / Decoder
Text to Encode
Encoded Result
Encoded URL to Decode
Decoded Result
About URL Encoding
Percent Encoding
URL encoding (percent-encoding) replaces unsafe characters with % followed by two hexadecimal digits representing the character's ASCII/UTF-8 byte value. For example, space becomes %20, and & becomes %26.
Reserved Characters
Characters like ? # & = / : @ have special meanings in URLs as delimiters. When these characters appear in data (not as delimiters), they must be percent-encoded to avoid breaking the URL structure.
encodeURI vs encodeURIComponent
encodeURI: Encodes a complete URL, preserving reserved characters that are part of URL syntax.
encodeURIComponent: Encodes everything except alphanumeric and -_.!~*'() - use for query parameter values.
Common URL Encodings
Whitespace & Punctuation
Space → %20 (or +)
! → %21
" → %22
# → %23
$ → %24
% → %25
Special Characters
& → %26
' → %27
+ → %2B
, → %2C
/ → %2F
: → %3A
Delimiters
? → %3F
@ → %40
= → %3D
[ → %5B
] → %5D
\ → %5C
Safe Characters
These characters don't need encoding:
A-Z a-z 0-9
- _ . ~
(unreserved characters per RFC 3986)
URL Encoding FAQ
When should I use encodeURI vs encodeURIComponent?
Use encodeURI() when encoding a complete URL - it preserves characters like :, /, ?, &, = that are part of URL structure. Use encodeURIComponent() when encoding values for query parameters or path segments - it encodes all special characters including delimiters.
Example: For ?search=hello world&page=1, encode "hello world" with encodeURIComponent to get ?search=hello%20world&page=1
Why is space sometimes %20 and sometimes +?
Both represent a space, but in different contexts. %20 is the standard percent-encoding per RFC 3986. The + sign is used in application/x-www-form-urlencoded format (HTML form submissions). Most servers accept both, but %20 is more universally compatible. When decoding, both should be converted to spaces.
How are non-ASCII characters (like Chinese) encoded?
Non-ASCII characters are first converted to UTF-8 bytes, then each byte is percent-encoded. For example, "中" (U+4E2D) becomes UTF-8 bytes E4 B8 AD, which encodes to %E4%B8%AD. This ensures international characters work correctly in URLs across all systems.
What happens if I double-encode a URL?
Double-encoding occurs when an already-encoded URL is encoded again. For example, %20 becomes %2520 (the % is encoded as %25). This causes decoding issues - the server sees %20 as literal text instead of a space. Always check if data is already encoded before encoding, and decode only once.
URL Encoding in Different Languages
JavaScript
encodeURI(url)
encodeURIComponent(str)
decodeURI(url)
decodeURIComponent(str)
PHP
urlencode($str)
rawurlencode($str)
urldecode($str)
rawurldecode($str)
Python
urllib.parse.quote(str)
urllib.parse.quote_plus(str)
urllib.parse.unquote(str)
urllib.parse.unquote_plus(str)
Java
URLEncoder.encode(str, "UTF-8")
URLDecoder.decode(str, "UTF-8")
Note: Java's URLEncoder uses + for spaces