All posts

URL With Spaces: Why It Breaks and How to Fix It

September 19, 2026

Why URLs Can't Contain a Literal Space

A URL with spaces isn't technically valid — it's a string a browser or server must reinterpret before it can be used. The URI spec treats space as unsafe because it was historically used to separate tokens in text, so allowing it unencoded would make parsing ambiguous. The character has no reserved meaning within URI syntax, so it must be escaped into something the spec allows.

In practice, this plays out one of three ways. Modern browsers quietly encode the space the moment you hit enter, rewriting my file.pdf to my%20file.pdf behind the scenes. Some older systems, scripts, or command-line tools simply choke on the raw string. And the messiest outcome, which most people actually run into, is a broken link where the URL gets truncated at the first space, because whatever's parsing it assumes the string ended there. A link posted in a chat app, embedded in an email, or hardcoded in HTML without encoding can shatter into two fragments, and only the first one goes anywhere.

Understanding this behavior is the first step in diagnosing seemingly random 404s, and it sets up the more useful question: how the space actually gets represented once encoded.

%20 vs + : The Two Ways Spaces Get Encoded

This is where most confusion lives. There are two different, non-interchangeable conventions, and mixing them up causes bugs that are annoying to trace.

%20 is the standard percent-encoding defined by RFC 3986, the actual URI specification. It converts space into its hexadecimal ASCII value and applies everywhere in a URL — path, query, fragment. Percent-encoding works this way for any character outside the allowed set, not just spaces: a slash, an ampersand, or a non-ASCII letter get the same treatment. Example: https://example.com/product page becomes https://example.com/product%20page.

+ is older and narrower. It comes from the application/x-www-form-urlencoded format used when HTML forms submit data, and it's only valid inside query strings — never in the path. A query string like ?search=blue+shoes is a form-encoding convention, not a general URI rule; a server has to know it's parsing form-encoded data to correctly interpret + as a space rather than a literal plus sign.

The practical takeaway: %20 is safe and correct everywhere. + only works reliably in query data that both ends of the request agree is form-encoded — mixing it into a path segment leaves a literal plus character sitting in your URL.

How to Fix or Encode Spaces in a URL

The right fix depends on which part of the URL has the space.

Slugs (the path portion). Don't encode a space here — replace spaces with hyphens instead. /blog/best running shoes should become /blog/best-running-shoes, not /blog/best%20running%20shoes. Hyphens are readable, don't trigger encoding at all, and are the convention every major CMS and static site generator defaults to.

Query parameters and dynamic values. If a value is built programmatically — a search term, a filename, user input dropped into a link — never hand-roll the fix with a manual .replace(' ', '-') or similar. Use your language's built-in encoder: encodeURIComponent() in JavaScript, urlencode() in PHP, quote() from Python's urllib.parse. These correctly handle spaces along with every other character that needs escaping (ampersands, slashes, unicode), which a manual string replace will inevitably miss. Let the standard library do it.

Pasted or shared links. If you're copying a URL from a file path, document, or old system into an email, CMS field, or anchor tag, don't manually retype it with %20 inserted by hand. Paste it into your browser's address bar, copy the resulting encoded version, or run it through a dedicated URL encoder. Letting the browser or a proper tool handle the encoding avoids the double-encoding mess covered below, and avoids leaving a broken link for the next person who clicks it. If a mangled link is also triggering unexpected redirects, that's worth checking separately — see how to stop a site from redirecting for that specific failure mode.

Do Spaces in URLs Hurt SEO?

Not directly. A raw space in a URL gets percent-encoded before a crawler ever indexes it, so it doesn't "break" indexing the way a 404 or a blocked robots rule would. But the effect shows up indirectly, through readability and trust.

An encoded URL full of %20 sequences is harder to read at a glance — in a search snippet, a shared link, or a browser tab — and URL clarity is a small but real factor in click-through behavior. Google has been explicit that clean, descriptive URLs help both users and crawlers understand a page before they even open it: Google's own guidance on URL structure recommends hyphens as word separators over both raw spaces and underscores, because hyphens are treated as word boundaries while underscores can get read as a single joined string. So the SEO cost of spaces isn't a ranking penalty — it's cumulative friction in crawl efficiency, snippet readability, and shareability.

Quick Checklist: Keeping URLs Clean

A short set of habits covers nearly every case:

  • Use hyphens, not spaces or underscores, in slugs — standard practice across CMS platforms and search engines alike.
  • Keep slugs lowercase to avoid duplicate-URL issues from case sensitivity.
  • Encode dynamic values with a proper function (encodeURIComponent or your language's equivalent) — never a manual character swap.
  • Never hand-edit an already-encoded URL; check whether it's encoded before touching it, to avoid double-encoding.
  • Avoid trailing spaces or spaces around query parameters when building links programmatically.

These are worth baking into a CMS template or build pipeline rather than fixing one link at a time. Spaces are just one symptom of URL hygiene — broken links, redirect chains, and malformed parameters tend to travel together on a site that hasn't been audited in a while.

Frequently Asked Questions

Can a URL actually contain a space, or does it always get changed?

A URL can't contain a literal, unencoded space and still be valid under the URI spec — it always gets changed, either automatically by the browser (encoded to %20) or manually by whoever built the link. If nothing encodes it, the URL typically breaks or truncates at the space.

What does %20 mean in a URL?

%20 is the percent-encoded representation of a space character, based on its ASCII hexadecimal value (20 in hex). It's the standard, RFC 3986-compliant way to include a space anywhere in a URL — path, query, or fragment.

Is it better to use %20 or a plus sign for a space in a URL?

%20 is the safer, universally correct choice because it works in every part of a URL. A plus sign only represents a space within form-encoded query strings (application/x-www-form-urlencoded) and will be read as a literal "+" character anywhere else, including the path.

Do spaces or encoded spaces in a URL hurt my Google rankings?

Not directly — search engines encode spaces automatically before indexing, so they don't cause a ranking penalty on their own. They can still hurt indirectly by making URLs harder to read in search results, reducing click-through, and adding minor crawl inefficiency across a large site.

Should I use underscores, hyphens, or %20 when a page title has spaces?

Use hyphens. Google explicitly recommends hyphens as word separators in URL slugs because they're interpreted as spaces between words, while underscores are often read as joining words together, and raw spaces or %20 sequences are harder to read and share.

Why does my link show %2520 instead of %20?

%2520 means a URL got encoded twice — the % in %20 was itself percent-encoded into %25, producing %2520. This usually happens when a script or system encodes a URL that was already encoded, so it's worth checking whether a value is already escaped before applying an encoding function again.

Spaces are a small detail, but they're exactly the kind that compounds into broken links, redirect chains, and lost crawl budget across a larger site. If you want to see whether your own site has malformed URLs, broken links, or related technical issues, run it through Optimevra's audit tool or check the live demo to see what it catches, and take a look at pricing if you're ready to monitor site health on an ongoing basis.

Originally published on Rankevra.