Which mode do I need?
URLs may only contain a limited set of characters. Everything else, such as spaces, accents, & and #, must be written as percent-encoding: a percent sign followed by the two hex digits of each UTF-8 byte. The right amount of encoding depends on where the text goes.
- Component (
encodeURIComponent): encodes almost everything, including/ ? # & =. Use it for a single value that you put into a path segment or query parameter. - Whole URL (
encodeURI): keeps the characters that structure a URL (: / ? # & =) and encodes the rest. Use it to clean up a complete address that contains spaces or accents. - Form data: like component, but spaces become
+, as inapplication/x-www-form-urlencodedbodies and many query strings.
When you decode a full URL with a query string, the tool also lists each parameter name with its decoded value, which makes long tracking and redirect links easy to read.
Worked example
Encode the value café & crème as a component:
caf%C3%A9%20%26%20cr%C3%A8me
The letter é is two UTF-8 bytes (C3 A9), so it becomes %C3%A9. The ampersand became %26, which is vital: an unencoded & would be read as the start of the next parameter. In form mode the spaces would be + instead of %20.
Common mistakes
- Double encoding: encoding text that is already encoded turns
%20into%2520. If you see that, decode once. - Using the whole-URL mode on a value: a value containing
&or=will not be escaped and will corrupt the query string. - Plus versus %20: a plus means a space only in form-encoded data; in a path it is a literal plus.
- Malformed input: a lone
%or a broken UTF-8 sequence cannot be decoded. The tool tells you instead of guessing.
Related: Base64 and HTML entities.
Frequently asked questions
What is the difference between encodeURI and encodeURIComponent?
encodeURI leaves URL structure characters like / ? & = # untouched, so it is for whole addresses. encodeURIComponent encodes them too, so it is for individual values inside a URL.
Why do I see %20 in some URLs and + in others?
Both mean a space but in different contexts. %20 works everywhere. A plus means a space only in form-encoded query strings and request bodies.
How are non-English characters encoded?
They are converted to UTF-8 bytes and each byte is written as %XX. For example, the euro sign becomes %E2%82%AC.
Is my URL sent anywhere?
No. Encoding and decoding use your browser's built-in functions. The text is not uploaded, stored or added to the page address.