Formula
unsafe byte → %XX (two hexadecimal digits of the UTF-8 byte)
- Letters, digits and - _ . ~ are never encoded.
- A space is %20 (or + in form encoding).
Every character that could confuse a URL is replaced by a percent sign and its byte value.
Worked example
Encode a query value
- Mode
- Encode a component (query value, path segment)
- Input
- name=Ada Lovelace & co/é
Encoded text
name%3DAda%20Lovelace%20%26%20co%2F%C3%A9
Length: 41 characters
name%3DAda%20Lovelace%20%26%20co%2F%C3%A9
How it works
Choose “component” when encoding a single value, such as a search term inside a query string: it encodes everything that has a special meaning in a URL, including / ? & = and #. Choose “full URL” when you already have a complete address and only want spaces and non-ASCII characters escaped, leaving its structure alone.
Non-ASCII characters are encoded as their UTF-8 bytes, so é becomes %C3%A9. When decoding, a stray % that isn't followed by two hex digits is reported with its position. HTML form submissions use + for spaces, which is why that option exists. For other encodings see Base64 Encode and Decode, and for formatting the data inside a request see JSON Formatter.
Assumptions and limits
- Follows the browser's encodeURIComponent / encodeURI rules.