Text Utils
By ToolzBank Team•
2 min read
•Monday, October 19, 2026•Updated Monday, October 19, 2026

URL Encoding Explained: How to Encode and Decode URLs

Why spaces become %20, when to use encodeURIComponent vs encodeURI, and how to encode, decode and inspect URLs and query strings instantly.

#url encode#url decode#percent encoding#encodeuricomponent

Paste a link with spaces or special characters into a browser and you will see things like %20 and %26 appear. That is URL encoding, also called percent-encoding. It keeps URLs valid when they contain characters that have a special meaning or are not allowed.

How percent-encoding works

Each unsafe character is replaced by % followed by its byte value in hexadecimal. A space becomes %20, & becomes %26, = becomes %3D and / becomes %2F. Non-English characters are first converted to UTF-8 bytes, so é becomes %C3%A9.

encodeURIComponent vs encodeURI

  • encodeURIComponent encodes everything except letters, digits and - _ . ! ~ * ' ( ). Use it for a single value you put into a URL, such as a search term in ?q=.
  • encodeURI leaves URL structure characters like : / ? & = # alone, so a full link keeps working. Use it for a whole URL that only needs spaces and similar characters fixed.

Using encodeURI on a query value is a common bug: a value containing & splits into two parameters.

%20 or + for spaces?

In paths and most of a URL, a space is %20. HTML forms submitted as application/x-www-form-urlencoded send spaces as +. Servers usually accept both in the query string, but not in the path.

How to encode, decode and inspect a URL

  1. Open the URL Encoder / Decoder.
  2. Choose Encode or Decode, and Component or Full URL mode; turn on "Spaces as +" for form encoding.
  3. Paste your text — the result updates as you type.
  4. For a full URL, the breakdown shows the protocol, host, path, hash and every query parameter, decoded.

Frequently Asked Questions

Why does a space become %20 in a URL?

Spaces are not allowed in URLs, so they are percent-encoded as %20 — the hexadecimal value of the space character.

When should I use encodeURIComponent?

Use it for any single value you insert into a URL, such as a query parameter, so characters like & and = inside the value do not break the URL.

Why do I get a malformed URI error when decoding?

The text has a % sign that is not followed by two hex digits, or a sequence that is not valid UTF-8. Look for a stray % in the input.

Is my URL sent anywhere?

No. Encoding and decoding happen in your browser.