URL 编解码

在线 URL 编码/解码工具,实时转换

方向
输入
0 字符
结果
0 字符

What is URL Encoding?

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.

Why Is URL Encoding Needed?

  • Transmission Safety: Ensures special characters don't break the semantic structure of the HTTP protocol.
  • Cross-Platform Compatibility: Different operating systems and browsers handle non-ASCII characters differently; encoding standardizes them.
  • Data Integrity: Prevents characters like spaces and quotes from being truncated or misinterpreted during transmission.
  • Security Protection: Proper encoding helps prevent certain injection attacks (e.g., CRLF injection).

URL Encoding Rules

Reserved Characters

The following characters have special meanings in URLs and must be encoded when not used as delimiters:

CharacterEncodedMeaning in URL
Space%20 (or +)Word separator
!%21-
"%22-
#%23Fragment identifier (anchor)
$%24-
%%25Encoding prefix
&%26Parameter separator
'%27-
(%28-
)%29-
*%2A-
+%2BSpace (in query strings)
,%2C-
/%2FPath separator
:%3AScheme/port separator
;%3B-
=%3DKey-value separator
?%3FQuery string start
@%40User info separator
[%5BIPv6 address
]%5DIPv6 address

Non-ASCII Characters

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:

  • "Hello" → %48%65%6C%6C%6F
  • "你好" → %E4%BD%A0%E5%A5%BD
  • "😀" → %F0%9F%98%80

encodeURI vs encodeURIComponent

JavaScript provides two URL encoding functions with important behavioral differences:

PropertyencodeURI()encodeURIComponent()
PurposeEncode a complete URLEncode URL parameter values
Characters NOT encodedA-Z a-z 0-9 - _ . ! ~ * ' ( ) ; / ? : @ & = + $ , #A-Z a-z 0-9 - _ . ! ~ * ' ( )
Typical scenarioEncoding a full URL containing non-ASCII charactersEncoding the value portion of a query string
ExampleencodeURI("https://example.com/你好") → https://example.com/%E4%BD%A0%E5%A5%BDencodeURIComponent("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.

Common Use Cases

  • GET Request Parameters: Passing non-ASCII or special characters in URL query strings (e.g., ?q=%73%65%61%72%63%68).
  • Form Data Submission: When submitting forms with application/x-www-form-urlencoded, the browser automatically URL-encodes the data.
  • Frontend Routing: Dynamic route parameters in SPAs (e.g., /user/%4A%6F%68%6E).
  • API Calls: When RESTful API path or query parameters contain special characters.
  • URL Parsing & Construction: Using JavaScript's URL and URLSearchParams APIs to parse and construct parameterized URLs.

URL Decoding

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.

URL Structure Parsing

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.

Why Choose Our URL Encoder/Decoder Tool?

  • Real-Time Conversion: Instant conversion as you type — no button click needed, ultra-low latency.
  • Bidirectional Switching: Toggle between encoding and decoding with one click, easily comparing original content with results.
  • URL Parser: Integrated URL structure analysis — automatically breaks down scheme, host, port, path, and parameters.
  • One-Click Copy: Each component has its own copy button for quick access.
  • Completely Free: No registration, no installation, no ads, unlimited usage.
  • Privacy Safe: All processing happens locally in your browser — your data never leaves your device.