What is URL encoding?
URLs may only contain a limited set of ASCII characters, and several of those — / ? # & = + — have special meaning. URL encoding, properly called percent-encoding, writes any other character as % followed by two hexadecimal digits for each of its UTF-8 bytes. A space becomes %20, & becomes %26 and é (two bytes in UTF-8) becomes %C3%A9.
The hard part is knowing which characters to encode, because it depends on where the text is going. A value inside a query string must have & and = encoded or it will break the parameter list, while a full URL must keep them. That is why JavaScript has both encodeURIComponent and encodeURI, why HTML forms use yet another variant with + for spaces, and why OAuth and AWS signatures demand strict RFC 3986 encoding.
This encoder implements all five modes exactly as the corresponding standards and browser functions do, and its table lists every character that was changed with its code point and UTF-8 bytes — handy when you are debugging why two systems produce different URLs.
How to use the URL Encoder
- Paste the text to encode — a parameter value, a path segment or a complete URL — or click Sample.
- Choose the encoding mode that matches where the result will go (see the guide below). The hint under the menu lists which characters are kept.
- Tick Encode each line separately to encode a list of values at once while keeping one result per line.
- Copy the result, and check the What was encoded table to see exactly what changed.
Example
The same input in three modes. Note how &, = and / survive only in full-URL mode, and how form encoding turns spaces into +:
Input: a b&c=d/é
encodeURIComponent: a%20b%26c%3Dd%2F%C3%A9
encodeURI: a%20b&c=d/%C3%A9
Form data: a+b%26c%3Dd%2F%C3%A9Which mode should I use?
- Query value / path segment — the default and the right choice in most cases: encode each parameter value (or path segment) separately, then join them with
&,=and/yourself. Equivalent toencodeURIComponent. - Full URL — only for tidying an entire URL that contains spaces or non-ASCII characters while keeping its structure. It does not encode
&or#, so never use it for individual values. Equivalent toencodeURI. - Form data — matches HTML form posts and
URLSearchParams, with+for spaces. Use it forapplication/x-www-form-urlencodedrequest bodies. - Strict RFC 3986 — also encodes
! ' ( ) *. Required when building OAuth 1.0 signature base strings and AWS Signature Version 4 canonical requests.
Common mistakes
- Double encoding: encoding an already-encoded string turns
%20into%2520. Encode raw values once, at the moment you build the URL. The URL Decoder can unwrap double-encoded text. - Encoding the whole URL with encodeURIComponent: this escapes
://and every/, producing a string that is no longer a URL. - Assuming + means space everywhere: only form-encoded data treats
+as a space. In a path,+is a literal plus sign.
Frequently Asked Questions
What is the difference between encodeURI and encodeURIComponent?
encodeURIComponent encodes all reserved characters, including / ? : @ & = + $ , #, so the result is safe as a single query value or path segment. encodeURI leaves those characters alone because it assumes it is processing a complete URL.
Should spaces be %20 or +?
Use %20 everywhere in URLs. + means space only in application/x-www-form-urlencoded data — HTML form submissions and query strings parsed as form data. Most servers accept both in query strings, but only %20 is correct in paths.
Why are non-English characters encoded as several %XX groups?
Percent-encoding works on bytes, and modern URLs use UTF-8, where characters outside ASCII take two to four bytes. € is three bytes (%E2%82%AC) and most emoji are four.
How do I build a URL with campaign tracking parameters?
The UTM Builder assembles and encodes utm_source, utm_medium and utm_campaign for you.
Is URL encoding the same as HTML entity encoding?
No. Percent-encoding makes text safe inside URLs; HTML entities such as & make text safe inside HTML. A URL placed in an HTML attribute may need both. For the HTML side, use the HTML Entity Encoder.