About Me

header ads
Advertisement

URL Encoding Explained: Why %20 Appears in Links

URL Encoding Explained: Why %20 Appears in Links

Ever copied a link and found %20 or %26 in it? That is URL encoding, also called percent-encoding. It keeps links working when they contain characters that have special meaning or are not allowed in a URL.

Why it is needed

URLs can safely contain only a limited set of characters. Characters like spaces, &, ?, #, and non-English letters need to be converted so browsers and servers read them correctly. Each unsafe character becomes a % followed by two hexadecimal digits.

Common examples

CharacterEncoded
Space%20
&%26
=%3D
?%3F
#%23
/%2F
é%C3%A9

A practical example

Say you want to pass the search phrase coffee & tea in a link:

https://example.com/search?q=coffee & tea breaks, because the space and & confuse the browser.

The correct version is:

https://example.com/search?q=coffee%20%26%20tea

In query strings, a space is sometimes written as + instead of %20. Both are common, but %20 is safer in most places.

Reserved vs unreserved characters

  • Unreserved (safe): letters, digits, -, _, ., and ~
  • Reserved (special meaning): : / ? # [ ] @ ! $ & ' ( ) * + , ; =

Reserved characters only need encoding when you want them treated as data rather than as URL structure.

Encode or decode instantly

Use a URL encoder and decoder to convert text in either direction. If you are creating clean addresses for blog posts or pages, a slug generator will turn a title into a tidy, URL-friendly slug without encoding headaches.

Mistakes to avoid

  1. Double encoding: encoding an already-encoded string turns %20 into %2520.
  2. Encoding the whole URL: usually you should encode individual parameter values, not the full link including https://.
  3. Forgetting non-ASCII characters: names with accents or non-Latin scripts must be encoded as UTF-8 bytes.
  4. Putting secrets in URLs: query strings can appear in logs and browser history. Do not put passwords or tokens in them.

Tips for clean URLs

  • Use lowercase letters and hyphens in page paths.
  • Keep slugs short and readable.
  • Avoid spaces and special characters in file names you plan to link.