URLs & Slugs

URL Encoding (Percent-Encoding) Explained

What percent-encoding is, which characters must be encoded in URLs, common codes like %20, and how to avoid encoding problems.

URLs can only contain a limited set of characters. Anything else, such as spaces, many symbols and non-ASCII letters, must be converted into a safe form called percent-encoding, also known as URL encoding.

How it works

Each unsafe character is converted to its byte value in UTF-8 and written as a percent sign followed by two hexadecimal digits.

CharacterEncoded
Space%20 (or + in form data)
&%26
/%2F
?%3F
#%23
é%C3%A9

Reserved characters

Some characters have special meanings in URLs:

  • ? starts the query string.
  • & separates parameters.
  • = separates a parameter name and value.
  • # starts a fragment (an in-page link).
  • / separates path segments.

If these characters appear as data rather than structure, they must be encoded.

Where problems appear

  • Spaces in file names producing links like My%20Document%20Final.pdf.
  • Ampersands in titles breaking query strings.
  • Accented characters creating long encoded links when copied.
  • Double-encoding, where %20 becomes %2520.

Avoiding encoding issues

  1. Use clean slugs with only lowercase letters, numbers and hyphens. The slug generator produces exactly this, so slugs never need encoding.
  2. Rename files before uploading: no spaces or special characters.
  3. Use built-in functions in code, such as encodeURIComponent() in JavaScript or rawurlencode() in PHP, rather than encoding by hand.
  4. Encode each parameter value once, not the whole URL repeatedly.

Frequently asked questions

What is percent-encoding?

What is percent-encoding? It replaces unsafe characters with a percent sign and two hexadecimal digits. URL encoding explained simply: a space becomes %20 and é becomes %C3%A9.

Why avoid spaces in URLs?

Spaces in URLs become %20, which looks messy and breaks when copied into some apps. Special characters in URLs such as &, ? and # have special meanings and also need encoding. Clean slugs avoid both problems, unlike an encoded URL.

Try the free Slug Generator

Turn titles into clean, SEO-friendly URL slugs with bulk mode and smart trimming.

Open Slug Generator