Ctrl K

URL Encoding Explained (Percent-Encoding)

beginner TheToolSera Team 6 min read Updated 8 May 2026

URLs may only contain a restricted set of ASCII characters, and some of those characters have structural meaning. Percent-encoding is how everything else — spaces, accents, ampersands, emoji — travels safely inside a link.

How percent-encoding works

Each unsafe byte is written as a percent sign followed by two hexadecimal digits. A space is byte 0x20, so it becomes %20. Non-ASCII characters are first converted to UTF-8 bytes, then each byte is encoded: é is two bytes and becomes %C3%A9.

CharacterEncodedWhy it matters
space%20Breaks the URL when left raw
&%26Separates query parameters
=%3DSeparates key from value
?%3FStarts the query string
#%23Starts the fragment — everything after is never sent to the server
/%2FPath separator
+%2BMeans space in form encoding
%%25The escape character itself

encodeURI vs encodeURIComponent

This is the decision that causes most bugs. encodeURI is for a whole URL and deliberately leaves structural characters alone. encodeURIComponent is for one piece of a URL and encodes everything that could be structural.

const q = "coffee & cake?";

encodeURI("https://x.com/s?q=" + q);
// https://x.com/s?q=coffee%20&%20cake?   <- broken: & and ? survive

"https://x.com/s?q=" + encodeURIComponent(q);
// https://x.com/s?q=coffee%20%26%20cake%3F  <- correct

// Best of all, let the platform do it:
const url = new URL("https://x.com/s");
url.searchParams.set("q", q);

Rule of thumb: encode values, never whole URLs. If you are building a query string, use URLSearchParams and stop thinking about it.

%20 or +?

Both appear because two specifications overlap. In a path segment, a space must be %20. In an application/x-www-form-urlencoded query string — what HTML forms produce — a space is +, and a literal plus must be written as %2B. Decoders that treat + as a literal plus in query strings are a frequent source of mangled search terms.

Double encoding

Encoded twice
?q=coffee%2520%2526%2520cake
Encoded once
?q=coffee%20%26%20cake

The tell-tale sign is %25 followed by more hex digits: the percent sign of the first pass got encoded again. It normally happens when a value is encoded by application code and then again by a framework, proxy or template. Encode exactly once, at the boundary where the URL is assembled.

URL Encoder

Encode or decode URLs and query values, and spot double encoding immediately.

Try URL Encoder

Common mistakes

Using encodeURI on a query value

It leaves &, ?, = and # intact, so a value containing them silently breaks the parameter structure.

Encoding an already-encoded string

Decode first if you are unsure of the input's state, or better, track it explicitly.

Expecting the fragment to reach the server

Everything after # stays in the browser. Server-side code never sees it.

Hand-rolling encoders

Use URL and URLSearchParams. They implement the specification, including edge cases you will forget.

Frequently asked questions

What is %20 in a URL?

A percent-encoded space. Spaces are not allowed literally in a URL, so they are written as %20 (or + inside a form-encoded query string).

When should I use encodeURIComponent?

Whenever you insert a value into a path segment or query parameter. Use encodeURI only on a complete URL you assembled yourself.

How do I detect double encoding?

Look for %25 followed by two hex digits. Decoding the string twice and comparing the results also reveals it.

Do non-English characters need encoding?

Yes. They are converted to UTF-8 bytes and each byte is percent-encoded, though browsers often display the decoded form in the address bar.

Put this into practice

URL Encoder runs entirely in your browser — no upload, no account, no limits.

Open URL Encoder

Related tools

Related guides

All guides

Explore related topics