URL Encoding & Decoding: The Complete Guide
URL encoding (also called percent encoding) is the process of converting characters into a format that can be transmitted over the internet. If you've ever seen %20 in a URL, that's URL encoding at workβit represents a space character.
What is URL Encoding?
URLs can only contain a limited set of ASCII characters. Special characters, spaces, and non-ASCII characters must be encoded using percent-encoding.
Original: Hello World!
Encoded: Hello%20World%21
Original: email=user@example.com&name=John Doe
Encoded: email=user%40example.com&name=John%20DoeCommon Encoded Characters
Space β %20 or +
! β %21
" β %22
# β %23
$ β %24
% β %25
& β %26
' β %27
( β %28
) β %29
* β %2A
+ β %2B
, β %2C
/ β %2F
: β %3A
; β %3B
= β %3D
? β %3F
@ β %40
[ β %5B
] β %5DURL Component Encoding
JavaScript
// encodeURIComponent (for query parameters)
const param = "Hello World & Friends";
const encoded = encodeURIComponent(param);
// "Hello%20World%20%26%20Friends"
// encodeURI (for full URLs)
const url = "https://example.com/search?q=Hello World";
const encoded = encodeURI(url);
// "https://example.com/search?q=Hello%20World"
// Decoding
const decoded = decodeURIComponent(encoded);When to Use Which?
- encodeURIComponent: Query parameters, path segments
- encodeURI: Full URLs (preserves :, /, ?)
π Encode/Decode URLs Instantly
Use our free URL Encoder tool to encode query parameters, decode URLs, and handle special characters correctly.
Open URL Tool βCommon Mistakes
Mistake #1: Double Encoding
// WRONG
const param = encodeURIComponent(encodeURIComponent("Hello World"));
// "Hello%2520World" (double encoded!)
// RIGHT
const param = encodeURIComponent("Hello World");
// "Hello%20World"Mistake #2: Not Encoding at All
// WRONG (breaks with spaces/special chars)
const url = `https://api.com/search?q=${searchTerm}`;
// RIGHT
const url = `https://api.com/search?q=${encodeURIComponent(searchTerm)}`;Conclusion
URL encoding is essential for web development. Always encode query parameters, decode when reading them, and use the right function for the job.