tools / url
url/
URL encode / decode, plus split a full URL into its parts and a query parameter table.
Input
Encoded
Parse URL
Query parameters
| Key | Value |
|---|
What is URL encoding
URL encoding (percent-encoding) is the notation defined in RFC 3986: a character that cannot appear in a URL as is is split into UTF-8 bytes, and each byte is written as % plus two hex digits, so a space becomes %20. This page offers two encoding modes and decoding, and splits a whole URL into its parts.
How it works: convert to UTF-8, then write each byte as %XX
- Characters are first converted to UTF-8 bytes; a Chinese character is 3 bytes, so it becomes 3 groups of %XX.
- Characters that need no encoding stay as they are; every other byte is written as % plus two uppercase hex digits.
- The two encoding modes differ only in which symbols they keep: encodeURI also keeps URL structure symbols such as : / ? # & =, which encodeURIComponent encodes.
- Decoding goes the other way: consecutive %XX groups are turned back into bytes, which are then read as UTF-8 text.
- "Parse URL" uses the browser's built-in URL parser, which follows the WHATWG URL Standard to split a URL into protocol, host, port, path, query parameters and fragment.
Example
encodeURIComponent: the space, &, =, / and ? are all encoded, and the two Chinese characters become 6 groups of %XX:
- Input
- a b&c=中文/?
- Output
- a%20b%26c%3D%E4%B8%AD%E6%96%87%2F%3F
encodeURI: URL structure symbols stay as they are; only the Chinese characters and the space are encoded:
- Input
- https://example.com/路径?q=a b#top
- Output
- https://example.com/%E8%B7%AF%E5%BE%84?q=a%20b#top
Sources
FAQ
What is the difference between encodeURIComponent and encodeURI, and which one should I use?
Use encodeURIComponent for a parameter value or a single path segment, and encodeURI for a whole URL. The former also converts characters with special meaning such as : / ? & = # into %XX, so it is only meant for one piece of a URL; the latter keeps them, so the URL structure stays intact, but it does not touch a & or = inside a parameter value. Letters, digits and - _ . ! ~ * ' ( ) are left alone by both.
Why does a space become %20, and does + turn into a space when decoding?
Encoding here writes a space as %20, not +. When decoding, a + in the box stays as it is and does not become a space, because decodeURIComponent does not do that conversion; only the query parameter table under "Parse URL" treats + as a space, following form rules. To decode something like a+b from a form submission, replace the + with a space by hand first.
What should I do about "not a valid UTF-8 sequence" when decoding?
The %XX run is not UTF-8. The most common case is Chinese text encoded as GBK by an older site, such as %D6%D0; like the browser's decodeURIComponent, this tool only accepts UTF-8, so it reports an error and points to where it happened. GBK content can be converted with a tool that supports GBK, for example Python's unquote(s, encoding='gbk'). The same error appears when the text was cut off while copying, for example %E4%B8 missing its last byte.
What should I do about "% is not followed by two hex digits"?
The text contains a percent sign that was never encoded, such as 100% or 50%off. In URL encoding the percent sign starts an escape and must be followed by two hexadecimal digits. Change that % to %25 and decode again; the message tells you which character it is.
What if the result still contains %XX after decoding?
It was most likely encoded twice; for example, %2520 decodes once to %20. Decode it again: click "⇄ Use result as input" to move the result back into the input box, then click "Decode" once more.
Does the result match URL encoding in PHP, Python or Java?
Mostly, with some differences in the details. encodeURIComponent is close to PHP's rawurlencode and Python's urllib.parse.quote(s, safe=''), except that it leaves ! ' ( ) * unencoded. Java's URLEncoder and PHP's urlencode write a space as +, while this tool writes %20. When integrating with another system, go by the decoding rules the receiver actually uses.
Why does "Parse URL" say the protocol is missing, or show something different from what I typed?
Parsing needs a complete URL that starts with a scheme such as https://; a bare domain or path gives an error. The result comes from the browser's own URL parser, so it is normalized: the host is lowercased, the port shows "(default port)" when it is omitted or is the default, non-ASCII characters in the path appear as %XX with an extra row for the decoded path, and keys and values in the query table are already decoded.
Is the URL I enter sent to a server?
No. Encoding, decoding and parsing all happen in your browser, so tokens, phone numbers and other parameters inside the URL never leave it.