URL Encode and Decode

Encode or decode a URL, a query value, or a form body. UTF-8 matches encodeURIComponent. Pick GBK or another encoding when the other side is not Unicode.

Why URL encoding has three different buttons

A URL is several pieces with different rules. The path may contain a slash that must stay a slash. A query value may contain a slash that must become %2F. A form body uses + for a space, while a query string usually uses %20. Encoding the whole string with the wrong function is the usual reason a link opens the wrong page.

  • Query value matches encodeURIComponent. Use it for one parameter: a search term, an id, a redirect target.
  • Whole URL matches encodeURI. It leaves : / ? # alone and only escapes spaces and non-ASCII characters. Use it when you already have a full address.
  • Form body is application/x-www-form-urlencoded. Spaces become +. Use it when you are building a POST body, not a link.

How to use it

  1. Paste the raw text or the already encoded text.
  2. Choose Encode or Decode, then the style and the character encoding. Leave UTF-8 unless the other side names a different encoding.
  3. Turn on “One value per line” when you have a list of keywords and want each line encoded on its own. Slashes inside a line are still encoded.
  4. When decoding a form body, leave “Treat + as a space” on, or choose Form body. When decoding a normal query string, %20 already means space and a literal plus is rare.
  5. If you see “not valid percent-encoding”, a % is not followed by two hex digits. That often means the string was decoded once already, or it was cut at a %.

Characters people get wrong

Space is %20 in a URL and + in a form. A literal plus in a query value must be %2B, or the server will read it as a space. & and = must be encoded inside a value or they start the next parameter. With UTF-8, which is the default and what encodeURIComponent uses, Chinese and emoji become one % sequence per byte. 北京 is not one escape; it is several. If a legacy server expects GBK or Big5, choose that encoding: the same characters become different percent sequences. Hex treats the box as raw bytes and percent-encodes those bytes.

Do not encode a full URL with the query-value style. https:// becomes https%3A%2F%2F and the browser will not treat it as an address. Encode the pieces, then join them. For the bytes behind those percents, see string to bytes. For Base64, which is a different encoding, see Base64.

Questions

Why did my space become a plus?

You used the form-body style. That is correct for HTML forms and wrong for most links. Switch to Query value.

The decoded text still has %20 in it.

The string was encoded twice. Decode again. Stop when the text is readable.

Should I encode the whole query string at once?

No. Split on &, encode each value, and keep the & and = as separators. “One value per line” is the safe way to do a list.