URL Encode/Decode

Percent-encode or decode URL/query strings.

Frequently asked questions

What is URL encoding?

URL (percent) encoding replaces characters that are unsafe in a URL — spaces, ampersands, slashes and non-ASCII — with a percent sign and hex code, so the URL stays valid.

When do I need to URL-encode?

When putting arbitrary text into a query string, a path segment or a form value, so special characters are not misinterpreted.

What is the difference between encodeURI and encodeURIComponent?

encodeURI keeps characters that are valid in a full URL, such as slashes and question marks, while encodeURIComponent encodes them too. Use component encoding for individual query values and path segments.

Why is a space sometimes encoded as %20 and sometimes as a plus sign?

In the path and most contexts a space becomes %20, but in the query string of form submissions it is often encoded as a plus sign under the application/x-www-form-urlencoded rules. Both decode back to a space in the right context.

Do I need to encode the entire URL or just parts of it?

Encode the individual values you insert, such as a search term or a path segment, rather than the whole URL, otherwise you would also encode the separators like the colon and slashes that give the URL its structure.

Which characters are safe and do not need encoding?

Unreserved characters, namely the letters A to Z, the digits 0 to 9, and the hyphen, underscore, dot and tilde, never need percent-encoding. Everything else may need encoding depending on where it appears.