URL Problems

How to URL Encode Text: encodeURI vs encodeURIComponent

URL encoding replaces characters that are not allowed or have special meaning in a URL with a percent sign and two hex digits, such as %20 for a space. The most common mistake is using the wrong function for the job.

Last updated: 2 November 2026

Open URL Encoder and Decoder →

Step-by-step

  1. Decide what you are encoding: a whole URL, or a single value that goes inside a query string.
  2. For a whole URL, use Encode URL. It keeps characters such as / ? & = # that give the URL its structure.
  3. For one value, such as a search term or a redirect address, use Encode Component. It also encodes / ? & = # + and :.
  4. Paste your text, choose the option and copy the result.
  5. Test the final link in a browser and check that the receiving page reads the value correctly.

Two functions, two jobs

Encode URL uses JavaScript's encodeURI, which leaves the characters that structure a URL alone. Encode Component uses encodeURIComponent, which encodes almost everything except letters, digits and - _ . ! ~ * ' ( ).

Example: the value a b&c=d/e?f#g+h becomes a%20b%26c%3Dd%2Fe%3Ff%23g%2Bh with Encode Component. Encoding a whole address such as https://x.com/a b?q=a&b=c#h with Encode URL gives https://x.com/a%20b?q=a&b=c#h.

The ampersand problem

If a query value contains &, encoding it as a whole URL leaves the & in place, and the server reads it as the start of a new parameter. Always encode each value separately with Encode Component, then join the parameters.

Spaces: %20 or +

In a URL path, a space is %20. In form-style query strings, + can also mean a space. A literal plus sign in a value should be encoded as %2B so it is not read as a space.

USE THE TOOL

Finish the task with DevUtilityKits

Use the relevant online utility, check the result, and continue with your development workflow.

Open URL Encoder and Decoder →Open URL Analyzer →
FAQ

Frequently asked questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI keeps characters that structure a URL, such as / ? & = and #. encodeURIComponent encodes them, so it suits single values.

How do I encode a space in a URL?

A space becomes %20. In form-encoded query strings, a plus sign is also read as a space.

Why does my query parameter break at the ampersand?

An unencoded & starts a new parameter. Encode the value with encodeURIComponent so it becomes %26.

Should I encode the whole URL?

Only when the URL contains unsafe characters such as spaces. Encode individual query values rather than the finished URL.