Dev Tools

Why That URL With a Space in It Keeps Breaking (And How to Fix It)

A URL that works perfectly in one context suddenly breaks when it's passed through another — a link with a space in it gets cut off partway, a query parameter with an & in the value ends up splitting into pieces it shouldn't. This is almost always a URL encoding problem, and it's one of those issues that seems obscure until you know what's actually happening.

Why certain characters break URLs

A URL's structure relies on specific characters having special meaning — ? starts the query string, & separates parameters, = assigns a value, spaces aren't valid at all. If the content you're putting into a URL happens to contain one of those characters — say, a search query that includes an ampersand — the URL parser can't tell whether that character is part of your data or part of the URL's own structure. The result is a broken or misinterpreted URL.

What encoding actually does

URL encoding (also called percent-encoding) converts problematic characters into a safe, unambiguous representation — a space becomes %20, an ampersand becomes %26, and so on. This removes the ambiguity entirely: the URL parser can now clearly tell the difference between a literal & in your data and an & that's meant to separate parameters.

The two encoding modes, and why both exist

  • Encoding a full URL needs to leave structural characters (:, /, ?, &) alone, since they're doing their actual job of defining the URL's structure.
  • Encoding a single value going into a URL (like a search term or a query parameter's value) needs to encode those same characters, since here they're just data, not structure.

Using the wrong mode for the situation is a common source of subtly broken URLs — a value-encoding function used on a full URL will mangle the structural characters it should have left alone.

Using it

  1. Paste your text or URL.
  2. Choose encode or decode, and the appropriate mode for what you're working with.
  3. Copy the result.

Non-English characters follow the same rule

Accented letters and non-Latin scripts aren't valid raw URL characters either — they get encoded into their percent-encoded byte representation the same way spaces and ampersands do, which is why a URL containing non-English text often looks like a long string of %XX sequences once encoded.

Got a URL that's breaking somewhere? Try the URL Encoder/Decoder — everything happens in your browser, nothing is uploaded anywhere.

Try the tool URL Encoder / Decoder Encode or decode URLs and query strings instantly