URL Encoder and Decoder
Percent-encode or decode text three ways (component, whole URL, form with +), catch text that was encoded twice, and read a URL's parts and query parameters decoded.
Last checked
encodeURIComponent: for one query value or path segment. Encodes everything except A–Z a–z 0–9 - _ . ! ~ * ' ( ).
Encoded text or URL
Decoded
The result appears here as you type.
How to use it
- Pick Decode or Encode, then the rules: Component for one query value or path segment, Whole URL for a full address, Form for data an HTML form sent.
- Paste the text. The result appears as you type; copy it with the button.
- If you paste a full URL, its parts and every query parameter appear below, decoded. If the text was encoded twice, each decoding round is listed.
What it checks and why
A URL may only contain a small set of ASCII characters. Everything else, and every character that has a job in the URL such as ? & = # /, must be written as % followed by two hex digits for each UTF-8 byte when it appears inside a value. That is percent-encoding, defined in RFC 3986. The letter é is two UTF-8 bytes, so it becomes %C3%A9.
JavaScript has two built-in encoders and they differ on purpose. encodeURIComponent encodes the reserved characters too, so it is the right one for a single query value or path segment: a value of a&b=c stays one value. encodeURI leaves : / ? # & = alone because it assumes it is given a whole address. Using encodeURI on a value is a common bug, because an & in the value then splits it into two parameters.
HTML forms use a third set of rules, application/x-www-form-urlencoded, from the WHATWG URL Standard: a space becomes + instead of %20, and only * - . _ and letters and digits stay unencoded. URLSearchParams in JavaScript follows the same rules, which is why decoding a form body with decodeURIComponent leaves the + signs in place.
Double encoding happens when already encoded text is encoded again, often by a redirect, a tracking link or a CMS. The percent sign itself becomes %25, so %20 turns into %2520. The tool looks for %25 followed by two hex digits and shows each decoding round, so you can see how many layers there are.
Specs and sources
Limits
- Encoding always produces UTF-8. Legacy escapes such as %E9 for é can be decoded with the Windows-1252 option, but not written.
- Host names with non-ASCII letters use Punycode (xn--), not percent-encoding. The URL parts view shows the host the way the browser's URL parser returns it.
- Decoding a whole URL with encodeURI rules keeps escapes such as %2F and %26 as they are, because decoding them would change the URL's structure.
- The double-encoding check is a hint: a value can contain a literal %25 on purpose.
Questions
- Is %2B or + right for a plus sign in a query string?
- Write a literal plus as %2B. In form-encoded query strings a bare + means a space, so a phone number like +44 sent unencoded arrives as a space followed by 44.
- How do I URL encode a string in Python, PHP or JavaScript?
- In JavaScript use encodeURIComponent for a value. In Python use urllib.parse.quote(s, safe="") for a value (its default keeps /) or quote_plus for form data with + for spaces. In PHP use rawurlencode for RFC 3986 style %20, or urlencode for form style +.
- What is the difference between encodeURI and encodeURIComponent?
- encodeURIComponent encodes everything except letters, digits and - _ . ! ~ * ' ( ), so it is safe for one query value. encodeURI keeps the characters that build a URL, such as : / ? & = #, so use it only on a complete address.
- Should a space be %20 or +?
- Both are correct in different places. In a path and in most query strings a space is %20. In form data (application/x-www-form-urlencoded), which is what URLSearchParams writes, a space is +. Pick Form in the tool to use +.
- Why does my URL contain %2520?
- It was encoded twice. %20 is a space; encoding it again turns the % into %25, giving %2520. Paste it in Decode mode and the tool shows each round until the plain text is left.
- What does URIError: URI malformed mean?
- decodeURIComponent found a % that is not followed by two hex digits, or bytes that do not form valid UTF-8, such as a Latin-1 %E9. The tool shows where in the text that happens.
- Which characters do not need encoding in a URL?
- The unreserved characters from RFC 3986: A to Z, a to z, 0 to 9 and - . _ ~. Everything else should be encoded when it is part of a value.
- Is my text sent anywhere?
- No. Encoding, decoding and URL parsing all run in your browser, and nothing you paste is stored or sent to a server.