Spaces in URLs: %20 vs +

The space character is the most common reason to URL-encode anything. And it’s also the source of one of URL encoding’s most persistent confusions: there are two valid encodings for a space, %20 and +, and the choice between them depends on which part of the URL you’re encoding.

This article covers both, when to use each, and the bugs that come from mixing them up.

The two encodings

%20 is the canonical percent-encoded space. It works everywhere in a URL — path, query, fragment, anywhere. It’s defined by RFC 3986.

+ is a legacy convention from HTML form submissions. It represents a space inside application/x-www-form-urlencoded data — which means inside query strings of forms submitted via GET, and inside POST bodies with that content type.

Both are valid URL encodings, but they live in different URL contexts.

Where each one works

URL part %20 +
Path componentspaceliteral +
Query string valuespacespace
Fragment (#)spaceliteral +
Form POST bodyspacespace

The key insight: in path components and fragments, only %20 means space. + means literal plus sign. In query strings and form bodies, both + and %20 are accepted as space by most servers.

How browsers handle it

When you type a URL with a space directly into the address bar, browsers encode it as %20:

You type:        https://example.com/My Document
Browser sends:   https://example.com/My%20Document

When you submit an HTML form via GET, browsers encode spaces in values as +:

<form action="/search" method="get">
  <input name="q" value="hello world">
</form>

Browser sends:   /search?q=hello+world

This is why you see both in the wild — browsers themselves use both conventions depending on context.

What happens when you mix them up

Using + in a path

// Bad
const url = "/users/" + encodeURIComponent("John Doe").replace(/%20/g, '+');
// "/users/John+Doe"
// Server sees: user with name literally "John+Doe"
// — not "John Doe" — because + is literal in paths

Decoding a query value that has +

// User submitted form value: "C++ programming"
// Browser encoded as: q=C%2B%2B+programming
// Note: the literal + in C++ became %2B, the space became +

// Wrong decoding (with + as literal)
decodeURIComponent("C%2B%2B+programming")
// → "C++ +programming"   ← extra plus where space should be

// Right decoding (form-encoded variant: + → space)
"C%2B%2B+programming".replace(/\+/g, ' ').then(decodeURIComponent);
// → "C++ programming"

JavaScript’s decodeURIComponent doesn’t treat + as space. You have to handle that yourself or use URLSearchParams (which does).

The decoder behavior split

Different language decoders handle + differently:

Language Function + becomes
JavaScriptdecodeURIComponentliteral +
JavaScriptURLSearchParamsspace
Pythonunquoteliteral +
Pythonunquote_plusspace
PHPurldecodespace
PHPrawurldecodeliteral +
JavaURLDecoder.decodespace
Gourl.QueryUnescapespace

The pattern: functions named with “query” or “plus” treat + as space (form-encoded variant). Functions named “raw” or just URL leave + literal.

Encoding side: which function produces which

Language Function Space becomes
JavaScriptencodeURIComponent%20
JavaScriptURLSearchParams+
Pythonquote%20
Pythonquote_plus+
PHPurlencode+
PHPrawurlencode%20
JavaURLEncoder.encode+
C#Uri.EscapeDataString%20

Which one should you use?

For new code, prefer %20 everywhere. Reasoning:

  • Works in all URL contexts (path, query, fragment)
  • Stricter compliance with RFC 3986
  • Visually clearer — %20 obviously needs decoding; + looks like a literal
  • Avoids the +-or-space ambiguity in code review

Use + when you specifically need application/x-www-form-urlencoded compatibility:

  • Matching exactly what an HTML form would send
  • Building a POST body with form content-type
  • Working with an old API that explicitly requires it

What about literal plus signs?

If your data has a real + character (like “C++ programming”), encoding depends on context:

// In a path: + is already literal, but encoding it is safer
"/courses/C%2B%2B"
"/courses/C++"   // also accepted

// In a query value: must be encoded if you want literal +
"?q=C%2B%2B+programming"   // C++ programming
"?q=C+++programming"       // 3 spaces and "programming"  ← wrong

Quick decision tree

You’re encoding a space. Which to use?

  • Path or fragment? → %20
  • Query string, mimicking a browser form? → +
  • Query string, building API request? → either; pick %20 for cross-platform safety
  • Don’t know what context you’re in? → %20

You’re decoding a string. Was it form-encoded?

  • From a query string or form POST body? → yes, treat + as space
  • From a path? → no, treat + as literal
  • Unsure? → use the “Treat + as space” toggle on our decoder and see which result looks right

Found this useful? Try the URL decoder, the URL encoder, or browse all tools.

Common questions.

%20 is the universal answer — it works in every part of a URL. Use + only in form-encoded query strings, where it’s the expected space. In a path, + is a literal plus, so always use %20 there.

Two standards. RFC 3986 uses %20 everywhere; the application/x-www-form-urlencoded convention (HTML forms, URLSearchParams) uses +. The tool’s output depends on which one it follows.

Encode it as %2B. This matters most in form-encoded query strings, where an unencoded + would be read as a space — so a value like C++ must be sent as C%2B%2B.

In the query string, form-decoding rules apply and + is treated as a space by most servers. In the path, + stays a literal plus. The behaviour depends on which part of the URL the + appears in.

Sources & standards

  • RFC 3986 — URI Generic Syntax. The core URL standard: Section 2.1 defines percent-encoding, Section 2.2 the reserved characters, and Section 2.3 the unreserved set. rfc-editor.org/rfc/rfc3986 §2.1
  • WHATWG URL Standard. Defines the application/x-www-form-urlencoded serializer — the +-for-space convention used by HTML forms and URLSearchParams, distinct from RFC 3986. url.spec.whatwg.org

Honest scope: %20 is RFC 3986; the +-for-space convention is the separate WHATWG application/x-www-form-urlencoded standard.

From the blog.

About this page. Written and maintained by Sri Murugan Systems, the developer of urlencodedecode.com. Every technical claim on this page is verified against primary sources — the RFCs (3986, 3629, 4648, 7578), the WHATWG URL Standard, and official vendor or language documentation — rather than second-hand summaries. When a source contradicts a common assumption, we follow the source and note the discrepancy. Corrections: contactus@urlencodedecode.com.