在线 URL 编码/解码工具,实时转换
URL Encoding, also known as Percent-Encoding, is a mechanism that converts special characters, non-ASCII characters, and reserved characters in a URL into %XX format, where XX represents the hexadecimal byte value of the character in UTF-8 encoding. URL encoding is a core component of the HTTP protocol, ensuring URLs can be reliably and safely transmitted across various network environments.
According to RFC 3986, URLs may only contain a limited set of safe characters: English letters (A-Z, a-z), digits (0-9), and a few special characters (-, _, ., ~). Any characters outside this range — including non-ASCII characters like Chinese or Japanese, as well as characters with special meanings such as spaces, #, &, ? — must be encoded.
The following characters have special meanings in URLs and must be encoded when not used as delimiters:
| Character | Encoded | Meaning in URL |
|---|---|---|
| Space | %20 (or +) | Word separator |
| ! | %21 | - |
| " | %22 | - |
| # | %23 | Fragment identifier (anchor) |
| $ | %24 | - |
| % | %25 | Encoding prefix |
| & | %26 | Parameter separator |
| ' | %27 | - |
| ( | %28 | - |
| ) | %29 | - |
| * | %2A | - |
| + | %2B | Space (in query strings) |
| , | %2C | - |
| / | %2F | Path separator |
| : | %3A | Scheme/port separator |
| ; | %3B | - |
| = | %3D | Key-value separator |
| ? | %3F | Query string start |
| @ | %40 | User info separator |
| [ | %5B | IPv6 address |
| ] | %5D | IPv6 address |
Non-ASCII characters such as Chinese, Japanese, Korean, and emojis are first converted to their UTF-8 byte sequences, then each byte is percent-encoded. For example:
%48%65%6C%6C%6F%E4%BD%A0%E5%A5%BD%F0%9F%98%80JavaScript provides two URL encoding functions with important behavioral differences:
| Property | encodeURI() | encodeURIComponent() |
|---|---|---|
| Purpose | Encode a complete URL | Encode URL parameter values |
| Characters NOT encoded | A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , # | A-Z a-z 0-9 - _ . ! ~ * ' ( ) |
| Typical scenario | Encoding a full URL containing non-ASCII characters | Encoding the value portion of a query string |
| Example | encodeURI("https://example.com/你好") → https://example.com/%E4%BD%A0%E5%A5%BD | encodeURIComponent("name=John&age=25") → name%3DJohn%26age%3D25 |
Recommendation: Use encodeURI() when encoding an entire URL; use encodeURIComponent() when encoding individual parameter values, path segments, or query strings. In most cases, encodeURIComponent() is safer as it encodes a broader set of characters.
?q=%73%65%61%72%63%68).application/x-www-form-urlencoded, the browser automatically URL-encodes the data./user/%4A%6F%68%6E).URL and URLSearchParams APIs to parse and construct parameterized URLs.URL decoding is the reverse process of URL encoding — converting %XX encoded characters back to their original form. In JavaScript, this corresponds to the decodeURI() and decodeURIComponent() functions.
In real-world development, we often need to debug encoded URLs — turning garbled sequences like %48%65%6C%6C%6F back into readable text like "Hello". This is the core value of a URL decoding tool: quickly revealing the actual meaning of parameters, troubleshooting encoding issues, and verifying API request correctness.
A complete URL consists of the following components:
scheme://username:password@host:port/path?query=value#hash
This tool not only provides encoding/decoding functionality but also includes a built-in URL Parser: when you input a complete URL, it automatically breaks down the scheme, username, password, host, port, path, query parameters, and hash, displaying them in a clean table format for easy inspection.