<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Outfit:wght@600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">
πŸ’» Developer guide

URL Encoding Explained: Percent-Encoding, %20 vs +, and Clean URL Slugs

How percent-encoding works, which characters must be encoded, encodeURI vs encodeURIComponent, %20 vs +, double-encoding bugs and how to write clean slugs.

πŸ“… Published 2026-11-15⏱️ 7 min readπŸ› οΈ 3 free tools

A URL is a string with structure. Characters such as ?, &, =, # and / are not just text: they separate the path from the query, one parameter from the next, and the page from a fragment. When the same characters appear inside a value, for example a search for "fish & chips", they have to be escaped, or the server reads them as structure and the value is cut in half.

This guide explains the rules behind percent-encoding (RFC 3986), the difference between the JavaScript encoding functions, why spaces sometimes become %20 and sometimes +, how double-encoding happens, and how to avoid most of these problems by choosing clean URL slugs in the first place.

How percent-encoding works

Percent-encoding replaces a byte with a % sign followed by its value as two hexadecimal digits. A space is byte 0x20, so it becomes %20. An ampersand is 0x26, so it becomes %26. Hex digits are case-insensitive (%2f and %2F are equivalent), but RFC 3986 recommends uppercase, and normalising to uppercase makes logs and caches more consistent.

Non-ASCII characters are first converted to bytes using UTF-8, then each byte is encoded. The letter Γ© is two bytes in UTF-8 (C3 A9), so it becomes %C3%A9. An emoji is usually four bytes, so it becomes twelve characters of percent-encoding. Browsers show the decoded form in the address bar for readability, but the request that goes over the network contains the encoded bytes.

Domain names are the exception. Internationalised domain names are not percent-encoded; they are converted to Punycode, so mΓΌnchen.de is sent as xn--mnchen-3ya.de. Percent-encoding only applies to the path, query and fragment.

Original value       Encoded
fish & chips         fish%20%26%20chips
50% off              50%25%20off
a/b                  a%2Fb
cafΓ©                 caf%C3%A9
name=value           name%3Dvalue

Reserved and unreserved characters

RFC 3986 splits characters into groups. Unreserved characters never need encoding and should not be encoded: the letters A to Z and a to z, the digits 0 to 9, and the four symbols - . _ ~. Encoding them is allowed but produces a different-looking URL for the same resource, which can split caches and analytics.

Reserved characters have a job in URL syntax. Whether they must be encoded depends on where they appear: a / is fine as a path separator but must be %2F if it is part of a single path segment value, and & is fine between query parameters but must be %26 inside a parameter value.

  • General delimiters: : / ? # [ ] @. These split the URL into scheme, host, path, query and fragment.
  • Sub-delimiters: ! $ & ’ ( ) * + , ; =. These are used inside components, most commonly & and = in query strings.
  • Everything else, including spaces, quotes, < >, backslashes, % itself and any non-ASCII character, must always be encoded.
  • A literal % must be written as %25. Forgetting this is why a value like "50% off" often breaks: the parser sees %20 or %2 followed by a non-hex character and either decodes the wrong thing or rejects the URL.

encodeURI vs encodeURIComponent

JavaScript has two encoding functions, and picking the wrong one is the most common URL bug in front-end code. encodeURI is meant for a whole URL. It leaves the reserved characters ; , / ? : @ & = + $ # alone, because they are probably structure. encodeURIComponent is meant for a single value. It encodes those characters too, leaving only letters, digits and - _ . ! ~ * ’ ( ).

The rule is simple: build URLs from parts, and run encodeURIComponent on each value before you join them. Never run encodeURI on a string that already contains user input in the query, because an & or = typed by the user will survive and split the parameter.

Better still, let the platform do it. The URL and URLSearchParams APIs in browsers and Node.js encode values for you, and most HTTP libraries in other languages (requests in Python, HttpUrl in OkHttp, url.Values in Go) have an equivalent. Hand-built string concatenation is where encoding bugs come from.

const q = 'fish & chips';

// Wrong: the & splits the value
'https://example.com/search?q=' + encodeURI(q);
// -> https://example.com/search?q=fish%20&%20chips

// Right: encode the value on its own
'https://example.com/search?q=' + encodeURIComponent(q);
// -> https://example.com/search?q=fish%20%26%20chips

// Best: let URLSearchParams handle it
const url = new URL('https://example.com/search');
url.searchParams.set('q', q);
url.toString();
// -> https://example.com/search?q=fish+%26+chips

%20 or +? Spaces in query strings

The last line of the example above uses + for spaces, not %20. Both are correct, in different places. RFC 3986 says a space is %20 everywhere. HTML forms, however, submit data as application/x-www-form-urlencoded, an older format in which a space is written as +. Because forms have used it for decades, almost every server decodes + as a space in the query string.

Problems start when the two conventions are mixed. A literal plus sign in a value, such as a phone number +44 or the search C++, must be sent as %2B. If it is sent raw, a form-style decoder turns it into a space. In the other direction, decodeURIComponent in JavaScript does not convert + to a space, so a value encoded by a form and decoded with decodeURIComponent keeps its plus signs.

  • In paths, always use %20. A + in a path is a literal plus sign.
  • In query strings, %20 is always safe. + works only if the receiver uses form-style decoding, which most do.
  • Always encode a literal plus inside a value as %2B.
  • When decoding a form-encoded query by hand in JavaScript, replace + with a space first, then call decodeURIComponent. URLSearchParams does this for you.

Double encoding and other bugs

Double encoding happens when an already-encoded value is encoded again. The % in %20 becomes %25, so a space ends up as %2520. The receiving server decodes once and sees the text %20 instead of a space. Search terms show up with literal %20 in them, redirects fail, and tracking parameters stop matching their campaigns.

It usually comes from two layers each doing their job: a CMS that encodes a URL when saving it, then a template that encodes it again on output, or a redirect parameter that is encoded by the application and again by a link shortener. Fix it by deciding which layer owns encoding and making every other layer pass the value through unchanged.

  • Seeing %25 in a URL is a strong hint of double encoding, unless the original value genuinely contained a percent sign.
  • Decoding twice is the mirror bug: a user who searches for 100%25 ends up with 100%, and a crafted value can turn into characters the first check never saw. Decode exactly once, at the boundary.
  • Validate after decoding, not before. A filter that blocks ../ in the raw URL can be bypassed with %2E%2E%2F if the check runs before the decode.
  • Redirect targets passed in a parameter (return_to, next, url) must be encoded as a whole with encodeURIComponent, and checked against an allow-list after decoding to avoid open redirects.

Clean slugs avoid most encoding problems

The easiest URL to encode is one that does not need it. A slug made only of lowercase letters, digits and hyphens is the same encoded and decoded, reads well when shared, and never breaks in an email client or chat app that mangles special characters.

Search engines can index URLs with encoded non-ASCII characters, so a slug in Hindi or Japanese is not wrong. It does, however, turn into a long run of %XX codes when copied into many tools, which is why many sites transliterate or translate slugs into ASCII.

  • Use lowercase. Most servers treat paths as case-sensitive, so /About and /about can become two URLs for one page.
  • Separate words with hyphens. Google treats hyphens as word separators; underscores are less reliably split.
  • Transliterate accented letters (Γ© to e, ΓΌ to u) instead of dropping them, so the word is still readable.
  • Remove filler words such as a, the, and, of when they add nothing, but keep them if removing them changes the meaning.
  • Keep slugs short and stable. Changing a slug later needs a 301 redirect from the old URL.

A practical workflow

When a link misbehaves, paste it into the URL Encoder / Decoder and decode it to see what the parameters really contain; decode a second time if the result still has %XX codes in it, which tells you it was double encoded. When building links by hand, encode each parameter value separately before joining it into the query string.

For campaign links, the UTM Builder assembles the query string and encodes the values so you do not have to. For new pages, run the title through the Slug Generator to get a lowercase, hyphenated, ASCII-only path, then shorten it to the words that matter.

More guides you might like

Ready to try it?

Open the free URL Encoder / Decoder and apply what you just read. No sign-up, nothing uploaded.

Open URL Encoder / Decoder β†’

← All guides