Skip to content
Technology·1 min read·

URL encoder and decoder

Percent-encode text for a query string, or decode a percent-encoded string back to text.

The answer

Encoding uses encodeURIComponent, so spaces become %20 and reserved characters such as & and = are encoded. Decoding reverses a valid percent-encoded string.

Result

Encoded text

a%20b

What do you want to do next?

How this works

The encoder escapes every character that is not an unreserved URL character. Use it on one component, such as a query value, not on a full URL you want to keep readable.

The decoder rejects a % that is not followed by two hex digits. A plus sign is left as a plus sign. It is not treated as a space, because that convention belongs to HTML forms, not to percent-encoding.

Practical steps

  1. 1

    Choose encode when you are building a query value.

  2. 2

    Choose decode when you already have a percent-encoded string.

  3. 3

    Encode the value only. Leave the ? and & that separate the query in place.

Examples

  • Encode “a b”

    a%20b

Common mistakes

  • ×

    Encoding an entire URL, including https://, and then wondering why it no longer opens.

Frequently asked questions

Does a space become a plus?

No. A space becomes %20. A plus is encoded as %2B.

Should I encode the whole URL?

No. Encoding the scheme and the slashes will hide the structure of the URL.

Continue reading

Sources