What URL encoding is
URLs may only contain a limited set of ASCII characters, and some characters such as ?, &, = and # have structural meaning. Percent-encoding (RFC 3986) represents any other byte as % followed by two hexadecimal digits. Text is first converted to UTF-8, so a non-ASCII character becomes several escapes: é → %C3%A9.
Which mode should I use?
| Mode | Use it for | Example: a b&c/é |
|---|---|---|
| Component | A single query value, path segment or fragment. | a%20b%26c%2F%C3%A9 |
| Full URI | A complete URL that already has the right structure but contains spaces or non-ASCII text. | a%20b&c/%C3%A9 |
| Form (+) | HTML form bodies and query strings built with URLSearchParams (application/x-www-form-urlencoded). | a+b%26c%2F%C3%A9 |
The most common bug is using the full-URI mode (or encodeURI) on a query value: characters like & and = are left alone and break the query string. Encode each value separately with the component mode, then assemble the URL.
Plus signs and spaces
In form encoding a space is written as +, and a literal plus sign as %2B. In ordinary percent-encoding + is just a plus sign. If decoded text shows + where you expected spaces, switch to the Form mode; if real plus signs turn into spaces (a common problem with phone numbers and base64 values in query strings), the sender used the wrong encoding.
Decoding errors
Decoding fails when a % is not followed by two hex digits, or when the escaped bytes are not valid UTF-8 (for example a lone %C3). The tool shows where the first bad sequence is. Strings encoded in a legacy charset such as Latin-1 cannot be decoded as UTF-8.
Encoding in code
// JavaScript
encodeURIComponent("a b&c"); // "a%20b%26c"
new URLSearchParams({ q: "a b&c" }).toString(); // "q=a+b%26c"
# Python
from urllib.parse import quote, urlencode
quote("a b&c", safe="") # 'a%20b%26c'
urlencode({"q": "a b&c"}) # 'q=a+b%26c'