Percent-encoding, explained
URLs can only contain a limited set of ASCII characters. Everything else (spaces, accented letters, emoji, and characters with special meaning such as &, =, ? and #) must be percent-encoded: each byte of the character’s UTF-8 form is written as % plus two hex digits. A space becomes %20, “é” becomes %C3%A9.
Two encoding modes
- Query value / path part (
encodeURIComponent, plus! ' ( ) *for RFC 3986 strictness): encodes everything except letters, digits and- _ . ~. Use it for a single parameter value or path segment (this is the one you usually need). - Whole URL (
encodeURI): leaves: / ? # & =alone so a complete address keeps working, and only encodes characters that are never valid.
Spaces as + follows the application/x-www-form-urlencoded convention used by HTML forms. When decoding, + is turned back into a space if this is on.
Decoding is forgiving: invalid sequences such as a lone % or a broken byte sequence are left as they are instead of causing an error.
Worked example
Here is what the URL Encoder / Decoder returns for its built-in example. Settings used: Direction: Encode; Encode as: Query value / path part; Spaces as + (form data): off. Click Try an example in the tool above to load it, then change it as you like.
search term=café & croissants/100% fresh?search%20term%3Dcaf%C3%A9%20%26%20croissants%2F100%25%20fresh%3FQuestions
What is %20 in a URL?
A percent-encoded space. Spaces are not allowed in URLs, so they are written as %20 (or + in form data).
Should I use encodeURI or encodeURIComponent?
encodeURIComponent for individual values like query parameters; encodeURI only for a complete URL that must keep its structure.
Last reviewed · How Textkiln tools work