URL Encoder

Text ↔ percent-encoding

Mode

The fields are linked. encodeURIComponent is for a parameter value, encodeURI is for a complete address, «Form» works like application/x-www-form-urlencoded (space as +).

Why encode a URL

Spaces, non-Latin letters and reserved characters cannot be used freely in an address or a query string. Percent-encoding replaces them with sequences such as %20, so that the browser and the server read the original text unambiguously.

Choosing the wrong mode gives a different result: if you encode the whole URL as a single parameter, the slashes and «?» turn into percent sequences too, and the link stops being an address.

FAQ

Is the text sent to a server?

No. Encoding and decoding run in the browser; no request is sent to the server.

When do I need encodeURIComponent, and when encodeURI?

encodeURIComponent encodes the whole text, including «?», «&» and «=», and suits a single parameter. encodeURI keeps the address separators and encodes only unsafe characters in an already assembled URL.

What does the form mode do?

application/x-www-form-urlencoded encodes like encodeURIComponent, but a space is written as «+», as in HTML forms.