encodeURI vs encodeURIComponent

See the difference between encodeURI and encodeURIComponent on the same URL. Learn which one belongs in query values.

Part of the free URL Encoder. Runs in your browser — nothing is uploaded.

encodeURI vs encodeURIComponent

encodeURI is for a complete URL: it leaves :, /, ?, # and & alone. encodeURIComponent is for one piece of a URL: it encodes those too. Using the wrong one is a common source of broken links.

Worked example: The same URL, both functions

Input

https://example.com/search?q=a b

Both results

encodeURI:            https://example.com/search?q=a%20b
encodeURIComponent: https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Da%20b

Practical tip

Rule of thumb: encodeURIComponent for values you insert; encodeURI only when the string is already a full URL with a few unsafe characters.

How to use this URL Encoder

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 3Copy the result, then adapt the same steps in your editor, script, or pipeline.

encodeURI vs encodeURIComponent FAQs

Which one should I use for a query value?

encodeURIComponent. encodeURI would leave & and = in the value, which split the query.

What about path segments?

encodeURIComponent, then join with /. That encodes slashes that belong to the data.