Input Text
Result
URL Encoding Knowledge
What is URL Encoding?
URL encoding (also known as percent-encoding) is a mechanism that converts special characters in a URL into the %XX format, where XX is the hexadecimal representation of the character's ASCII/UTF-8 byte. The URL standard is defined in RFC 3986, which specifies that URLs may only contain ASCII letters, digits, and a few reserved characters. All other characters must be encoded.
When Do You Need URL Encoding?
- URL contains non-ASCII characters: Characters like accented letters or CJK characters need encoding
- Query parameter values contain special characters: Characters like
& = ?in values break the URL structure - Building API request URLs: Ensures parameter values are correctly transmitted and parsed
- URL redirects: Passing target URLs in
Locationheaders orredirectparameters - Anchor/fragment identifiers: Encoding special characters in the fragment portion
- mailto / tel links: Special characters in email subjects or bodies need encoding
encodeURI vs encodeURIComponent
JavaScript provides two URL encoding functions. The core difference is how they handle reserved characters:
β’ encodeURI: Encodes a complete URL, preserving structural characters ; , / ? : @ & = + $ #. Use this when encoding a full URL address.
β’ encodeURIComponent: Encodes a URL component (such as a parameter value), encoding all reserved characters, ensuring that special characters in the value do not break the URL structure.
Simple rule: Use encodeURI for entire URLs, use encodeURIComponent for parameter values.
URL Encoding Reserved Character Table
| Character Type | Characters | encodeURI | encodeURIComponent |
|---|---|---|---|
| Alphanumeric | A-Z a-z 0-9 | Preserved | Preserved |
| Unreserved symbols | - _ . ! ~ * ' ( ) | Preserved | Preserved |
| URL structure chars | ; , / ? : @ & = + $ # | Preserved | Encoded as %XX |
| Space | (space) | Encoded as %20 | Encoded as %20 |
| Unicode chars | e.g. CJK | Encoded as %XX | Encoded as %XX |
| Other special chars | < > " { } | \ ^ ` | Encoded as %XX | Encoded as %XX |
Common Use Cases
- API parameters:
?q=(search keyword encoded as a parameter value) - URL redirects:
?redirect=(target URL encoded as a parameter value, use encodeURIComponent) - Anchor navigation:
#(encode special characters in the fragment) - mailto links:
mailto:?subject=(encode email subject) - Path segments:
/path/(encode path segment with special characters)
How much does URL encoding increase length?
Each encoded character becomes 3 characters (e.g. a space becomes %20). Characters that occupy multiple bytes in UTF-8 will expand further β for example, a 3-byte CJK character becomes 9 characters after encoding. URLs containing many non-ASCII or special characters will increase significantly in length after encoding.
Should I choose encodeURI or encodeURIComponent?
If you are encoding an entire URL (with protocol, domain, path), use encodeURI, which preserves :/?#&= and other structural characters. If you are encoding a specific parameter value or fragment within a URL, use encodeURIComponent, which encodes all special characters to prevent them from breaking the URL structure.
Does URL encoding support Chinese/Unicode?
Yes. JavaScript's encodeURI and encodeURIComponent automatically convert Unicode characters to percent-encoding using UTF-8. This tool fully supports Chinese, Emoji, and all Unicode characters.
What is a space encoded as? What is the difference between %20 and +?
encodeURI and encodeURIComponent encode a space as %20. In the application/x-www-form-urlencoded format (such as form submissions), a space is encoded as +. This tool uses the standard %20 encoding. If you need + encoding, you can replace it manually.
How do I use batch mode?
After checking "Batch mode", the tool processes each line in the input box separately, one URL per line. Empty lines are preserved. If a line fails to decode, an error message is shown for that line without affecting other lines.
Is URL encoding encryption? Is it secure?
No. URL encoding is an encoding scheme, not encryption. Anyone can decode it and it provides no security. Its purpose is to ensure that special characters in URLs are correctly transmitted and parsed, not to protect data. For secure transmission, use HTTPS or a real encryption algorithm.