URL Encoder/Decoder
Quickly encode and decode URLs with multiple encoding modes
Select Conversion Method
What is URL Encoding?
URL encoding (also known as percent-encoding) is a mechanism for converting characters into a format that can be safely transmitted in a URL. Since URLs can only contain specific characters from the ASCII character set, other characters (such as non-ASCII characters, spaces, and special symbols) need to be encoded as %XX format, where XX is the hexadecimal value of the character.
For example: a space is encoded as %20, and the Chinese character 你 is encoded as %E4%BD%A0.
Encoding Method Comparison
| Method | Purpose | Characters Not Encoded |
|---|---|---|
| encodeURIComponent | Encode URL parameter values | A-Z a-z 0-9 - _ . ! ~ * ( ) |
| encodeURI | Encode complete URLs | Preserves : / ? # [ ] @ ! $ & ( ) * + , ; = |
Recommendation:
- Encoding URL parameter values → Use encodeURIComponent
- Encoding complete URLs → Use encodeURI
FAQ
Q: What's the difference between encodeURIComponent and encodeURI?
A: The main difference is in the encoding scope. encodeURIComponent encodes more characters, including URL structural characters (like : / ? # etc.), making it suitable for encoding URL parameter values. encodeURI preserves URL structural characters, making it suitable for encoding complete URLs.
Q: Does a space encode to %20 or +?
A: In standard URL encoding, a space is encoded as %20. In application/x-www-form-urlencoded format (like form submissions), a space is encoded as +. This tool uses standard URL encoding, so spaces are encoded as %20.
Q: Why is URL encoding necessary?
A: URLs can only contain a limited set of ASCII characters. Non-ASCII characters, special symbols, and other characters would cause parsing errors or garbled text if placed directly in a URL. URL encoding converts these characters to %XX format, ensuring URLs are correctly transmitted and parsed in various environments.
Q: How to handle encoding errors?
A: If an invalid encoding format (such as incomplete %XX) is encountered during decoding, the tool will display an error message. Please ensure the input is a valid encoded string, or use the encoding function to regenerate the correct encoding.