Home / Tech / URL Encoder

URL Encoder/Decoder

Input
Output
AC
Reviewed by Alex Chen, Tech Lead
Last Updated: November 2025

URL Encoding Explained

URL encoding (percent-encoding) converts special characters into %XX format so they can safely appear in URLs. Spaces become %20, exclamation marks become %21, etc.

Quick Example:
Before: Hello World!
After: Hello%20World%21

💡 Expert Tip: Don't Encode the Entire URL

"The #1 mistake: encoding 'http://example.com' → 'http%3A%2F%2Fexample.com'. That's a broken URL." — Alex Chen

✅ Right: 'http://api.com?q=' + encodeURIComponent('search term')
❌ Wrong: encodeURIComponent('http://api.com?q=search term')

⚠️ Common Mistakes

1. Encoding the Entire URL

Running encodeURIComponent('http://example.com') produces 'http%3A%2F%2Fexample.com'—a useless string. Only encode query parameters and path segments, not protocols or domains.

2. Using Deprecated escape()

JavaScript's escape() is deprecated and doesn't follow URL encoding standards. It produces non-standard output like %u sequences. Always use encodeURI() or encodeURIComponent().

3. Double Encoding

Encoding 'Hello%20World' again produces 'Hello%2520World' (% → %25). Check if data is already encoded before encoding again.

4. Forgetting to Encode Special Characters in Query Params

'?name=John&age=30' looks fine, but '?email=user@example.com' breaks because @ needs encoding. Always use encodeURIComponent() for query values.

encodeURI vs encodeURIComponent

Feature encodeURI() encodeURIComponent()
Purpose Encode full URL Encode URL parts
Preserves : / ? # [ ] @ Only A-Z 0-9 - _ . ! ~ * ' ( )
Use case Complete URLs Query params, path segments

❓ FAQ

Why do spaces become %20?

In modern URL encoding, spaces become %20. The + for spaces is legacy from form data encoding. Use %20 for URLs—it's the standard.

📚 References