·
Igor Ilic
The developer's guide to URL encoding and decoding
What is URL encoding?
URL encoding (percent-encoding) is how special characters are represented in URLs. Certain characters have reserved meanings in URLs, and encoding ensures they are transmitted safely.
Which characters need encoding
URLs can only contain letters (A-Z, a-z), digits (0-9), and a few special characters (-, _, ., ~). Everything else must be percent-encoded:
- Spaces become
%20(or+in query strings) ?starts the query string#starts the fragment identifier&separates query parameters=separates param names from values- Unicode characters are encoded as UTF-8 bytes, then percent-encoded
How percent-encoding works
Each unsafe byte becomes %XX, where XX is its two-digit hexadecimal value:
- Space (ASCII 32, hex 0x20) →
%20 - The @ sign (ASCII 64, hex 0x40) →
%40 - The character 中 (U+4E2D) in UTF-8 →
%E4%B8%AD
Common mistakes
- Double encoding — encoding an already-encoded URL. Sending
%2520(%25+20) instead of%20 - Mixing form and URL encoding — form submissions encode spaces as
+, not%20 - Forgetting to encode query parameters — always encode dynamic values when building URLs
- Encoding the whole URL — only encode the parts with special characters, not the scheme or domain
JavaScript URL encoding
// Encode a URI component (query params, path segments)
encodeURIComponent("hello world & more")
// "hello%20world%20%26%20more"
// Encode a full URI (preserves scheme, domain)
encodeURI("https://example.com/path with spaces")
// "https://example.com/path%20with%20spaces"
// Decode
decodeURIComponent("%40sign")
// "@sign"
Use our URL tools
The URL encoder and URL decoder provide instant results with support for both standard URL encoding and form-encoding (spaces as +).