Developer Tools

URL Encoding Explained – Why Spaces Become %20

Paste a link with spaces, “&” or Urdu text and it can break. URL encoding fixes this by turning special characters into safe % codes.

In this article
  1. Why URLs need encoding
  2. Common encodings
  3. Component vs full URL
  4. How to encode
  5. Building a link with a search term
  6. Encoding in spreadsheets and code
  7. Do not encode twice
  8. URL encoding vs other encodings

Why URLs need encoding

Web addresses may only contain a limited set of characters. Some characters have special jobs: “?” starts the query, “&” separates parameters, “#” starts a fragment, “/” separates path parts. If your data contains those characters – or spaces, accents or non-Latin letters – it must be encoded so it is not mistaken for structure. Each byte is written as “%” plus two hexadecimal digits: a space becomes %20, “&” becomes %26.

URL EncoderPercent-encode text so it is safe inside URLs and query strings. Choose component or full-URL encoding and %20 or + for spaces. Live and free.
Open the free tool

Common encodings

CharacterEncoded
space%20 (or + in form data)
&%26
?%3F
#%23
/%2F
é%C3%A9
ا (Urdu alif)%D8%A7

Non-English letters become several % codes because they are encoded as UTF-8 bytes first.

Component vs full URL

This is where most mistakes happen. There are two modes – the same as JavaScript’s two functions:

  • Component mode (encodeURIComponent) encodes everything special, including “/”, “?” and “&”. Use it for a single value you are putting into a URL – a search term, a name, a redirect address.
  • Full-URL mode (encodeURI) leaves the structural characters alone and encodes only what is not allowed. Use it to clean up a whole address that contains spaces or accents.

Encoding a value with full-URL mode leaves “&” unencoded, so q=salt & pepper silently becomes two parameters. Encoding a whole URL with component mode turns “https://” into “https%3A%2F%2F”, which no longer works as a link.

How to encode

  1. Open the URL Encoder.
  2. Choose component or full-URL mode.
  3. Optionally use “+” for spaces, the style used by HTML forms in query strings.
  4. Type or paste – the output updates as you type.

Suppose you want a link that searches a site for “shoes & bags”. Encode just the term in component mode: shoes%20%26%20bags. Then build the link: https://shop.com/search?q=shoes%20%26%20bags. For marketing links with several parameters, the UTM Builder handles all of the encoding for you.

Encoding in spreadsheets and code

If you build links in bulk, most environments have a built-in function: Excel’s ENCODEURL(), Google Sheets’ ENCODEURL(), JavaScript’s encodeURIComponent(), Python’s urllib.parse.quote() and PHP’s rawurlencode(). Use this tool to check a few results by hand when something looks wrong.

Do not encode twice

Encoding an already-encoded string turns “%20” into “%2520” (the % itself gets encoded). If you see “%25” in a link, something was encoded twice. Decode it with the URL Decoder and encode once.

URL encoding vs other encodings

URL encoding is for addresses. For embedding text in HTML, use the HTML Entity Encoder; for turning binary data into text, use Base64. To see each part of a complex address, use the URL Parser.

URL EncoderPercent-encode text so it is safe inside URLs and query strings. Choose component or full-URL encoding and %20 or + for spaces. Live and free.
Open the free tool
Keep reading

Related articles

All articles
Dev

How to Read Messy Links Full of % Codes

Links copied from emails, search results and ads are often a jumble of percent codes. Decoding them shows what they really say – and where they really go.

3 min read
Web

The Anatomy of a URL – Every Part Explained

Web addresses look like random strings, but every part has a job. Understanding them helps with SEO, analytics, debugging – and spotting scam links.

3 min read
Dev

What Is Base64 – and When Should You Use It?

Base64 shows up in emails, web pages, API keys and data URIs. It is simple once you see what problem it solves – and what it does not do.

3 min read