Home β€Ί URL Encoder / Decoder & Query String Parser

URL Encoder / Decoder & Query String Parser

Output

Query string parser

What URL encoding does

URLs may only contain a limited set of ASCII characters. Everything else β€” spaces, accented letters, emoji, and characters that have a structural meaning such as &, =, ? and # β€” must be percent-encoded: the character is converted to UTF-8 bytes and each byte is written as % followed by two hex digits. For example cafΓ© becomes caf%C3%A9 and a space becomes %20.

Examples

InputencodeURIComponentencodeURI
a b&c=da%20b%26c%3Dda%20b&c=d
https://x.io/?q=1https%3A%2F%2Fx.io%2F%3Fq%3D1https://x.io/?q=1
100% πŸ˜€100%25%20%F0%9F%98%80100%25%20%F0%9F%98%80

Gotchas

Frequently asked questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI is meant for a full URL and leaves characters with special meaning in URLs (: / ? # & = +) untouched. encodeURIComponent is meant for a single value such as a query parameter and encodes those characters too. Use encodeURIComponent for parameter values; using encodeURI there breaks values that contain & or =.

Should a space be encoded as %20 or +?

In the path and in general percent-encoding, a space is %20. In HTML form data (application/x-www-form-urlencoded), which is also what URLSearchParams produces, a space is +. When decoding query strings that came from forms, enable 'Treat + as space'.

Why do I get 'URI malformed' when decoding?

decodeURIComponent throws when it meets a % that is not followed by two hex digits, or a sequence that is not valid UTF-8 (for example %E9 on its own, which is Latin-1 Γ©). Encode a literal percent sign as %25.

Which characters are never encoded?

encodeURIComponent leaves A-Z a-z 0-9 and - _ . ! ~ * ' ( ) unchanged. RFC 3986 considers only - _ . ~ as 'unreserved', so some strict APIs (for example OAuth 1.0 signatures) require encoding ! * ' ( ) as well; the 'RFC 3986 strict' option does that.