%url-decoder.net

URL Encoding a Space: + or %20?

Updated November 25, 2026 · 8 min read

Short answer

%20 is the encoding of a space that works everywhere in a URL. + means a space only in a query string that is read as form data (application/x-www-form-urlencoded), which is how HTML forms and most server frameworks read queries. In a path, + is a literal plus sign. When you generate URLs, %20 is the safe choice; when you need a literal plus in a query value, write %2B.

A space is not allowed in a URL, so it has to be encoded. You will see it written two ways, %20 and +, and the difference matters: getting it wrong turns plus signs into spaces, breaks file links and corrupts search terms. This guide explains where each form is valid, what every major language does with them, and which to use.

Two encodings, two specifications

%20 is ordinary percent-encoding from RFC 3986, the URI standard. A space is byte 0x20, so it is written %20. That rule applies to every part of a URL: path, query and fragment.

+ comes from a different format, application/x-www-form-urlencoded, the encoding HTML forms use for their fields. The WHATWG URL Standard defines it, and its serializer writes a space as +. When a form is submitted with method="get", the browser puts that form-encoded data into the query string, which is why + became common in queries.

So the question is never “which is correct” in general. It is: which format will the reader of this part of the URL use?

Where each one is valid

Part of the URL%20+
PathA spaceA literal plus sign
Query, read as form data (most frameworks)A spaceA space
Query, read with plain percent-decodingA spaceA literal plus sign
Fragment (after #)A spaceA literal plus sign

%20 means a space in every row. That is why it is the safe default when you write URLs. + is only a space when the reader knows the text is form data.

What each encoder produces for a space

Outputs from running each function; the reference page lists the runtime versions.

LanguageFunctionSpace becomes
JavaScriptencodeURIComponent%20
JavaScriptencodeURI%20
JavaScriptURLSearchParams+
JavaScriptescape (deprecated)%20
Pythonquote (default safe='/')%20
Pythonquote (safe='')%20
Pythonquote_plus+
C#Uri.EscapeDataString%20
C#WebUtility.UrlEncode+
C#HttpUtility.UrlEncode+

The split follows the two specifications. Functions meant for URL components (encodeURIComponent, Python's quote, C#'s Uri.EscapeDataString) write %20. Functions meant for form data (URLSearchParams, quote_plus, WebUtility.UrlEncode) write +.

What each decoder does with +

This is where bugs appear. Here is a+b%20c, which contains both forms, through common decoders:

LanguageFunctionResultSource
JavaScriptdecodeURIComponent"a+b c"Run
JavaScriptURLSearchParams.get"a b c"Run
Pythonurllib.parse.unquote"a+b c"Run
Pythonurllib.parse.unquote_plus"a b c"Run
C#Uri.UnescapeDataString"a+b c"Run
C#WebUtility.UrlDecode"a b c"Run
C#HttpUtility.UrlDecode"a b c"Run
PHPrawurldecode"a+b c"Documented
PHPurldecode"a b c"Documented
JavaURLDecoder.decode"a b c"Documented
Gourl.PathUnescape"a+b c"Documented
Gourl.QueryUnescape"a b c"Documented

JavaScript, Python and C# results were produced by running Node.js 18, Python 3.12 and .NET 8. PHP, Java and Go results are the behaviour their documentation describes. Note that Java's URLDecoder always treats + as a space: despite its name it decodes form data, so do not use it on paths.

The rule of thumb: if a decoder's name or documentation mentions forms, queries or “plus”, it turns + into a space. Plain URI decoders do not.

The literal plus sign problem

The real damage happens when a value contains a genuine +: a phone number, a C++ search, an email address such as name+tag@example.com, or Base64 data. Put it in a query unencoded and a form decoder turns it into a space:

new URLSearchParams("phone=+15550100").get("phone")
// " 15550100"

new URLSearchParams("phone=%2B15550100").get("phone")
// "+15550100"

Encoded as %2B, the plus survives every decoder. Every component encoder already does this: encodeURIComponent("+") returns "%2B". The bug only appears when a URL is assembled by hand or by string concatenation.

Base64 deserves a special mention because its alphabet includes + and /. A Base64 token pasted into a query unencoded arrives with spaces in place of its plus signs and fails to decode. Encode it, or use the URL-safe Base64 alphabet, which replaces + with - and / with _. The Base64 tool supports both.

The opposite problem: + in a path

Because + is common in queries, some code applies form encoding to a whole URL. A file named Q3 report.pdf then gets a link to /files/Q3+report.pdf. The server reads the path with plain percent-decoding, looks for a file named with a literal plus, and returns 404. Paths need %20:

"/files/" + encodeURIComponent("Q3 report.pdf")
// "/files/Q3%20report.pdf"

The two JavaScript URL setters disagree

Even inside one API you can get either form. Setting the query through searchParams uses form encoding; assigning the search string uses plain percent-encoding:

url.searchParams.set("q", "a b")   // https://example.com/?q=a+b
url.search = "q=a b"               // https://example.com/?q=a%20b

Both are read as "a b" by URLSearchParams, so this rarely causes a bug, but it explains why the same code base can produce both forms. If you compare URLs as strings, for example as cache keys, normalise them first.

Python, PHP and C# in one minute

  • Python: urlencode({'q': 'a b+c'}) gives q=a+b%2Bc. Pass quote_via=quote to get q=a%20b%2Bc. parse_qs decodes + as a space; unquote does not, unquote_plus does.
  • PHP: urlencode writes +, rawurlencode writes %20. The matching decoders are urldecode and rawurldecode.
  • C#: Uri.EscapeDataString writes %20; WebUtility.UrlEncode writes +. On the way back, Uri.UnescapeDataString keeps + and WebUtility.UrlDecode turns it into a space.

Which should you use?

  1. Writing URLs: use %20 unless you are reproducing an HTML form submission. It means a space everywhere, to every decoder.
  2. Writing query values that may contain +: always encode the plus as %2B. Component encoders do this for you.
  3. Reading a query string: use a query parser (URLSearchParams, parse_qs, your framework's request object), which treats + as a space as browsers expect.
  4. Reading a path: use plain percent-decoding, which keeps +.
  5. Signing requests: follow the specification exactly. Signature schemes compare encoded bytes, so + and %20 are not interchangeable there.

Try it

The URL Decoder has a Form scope that treats + as a space and a Component scope that does not, so you can see both readings side by side. Open an example and switch between them.

Questions

Is + or %20 correct for a space in a URL?

Both can be correct, in different places. %20 is valid in every part of a URL. + means a space only in a form-encoded query string. In a path, + is a plus sign.

Why do some URLs use + instead of %20?

HTML forms submitted with GET encode their fields as application/x-www-form-urlencoded, which writes spaces as +. That convention spread to query strings in general, and tools such as URLSearchParams, Python's urlencode and PHP's urlencode still produce it.

How do I send a literal plus sign in a query parameter?

Encode it as %2B. A raw + in a query value is read as a space by form-style parsers, so a phone number such as +1 555 arrives as " 1 555".

Does decodeURIComponent convert + to a space?

No. decodeURIComponent only decodes %XX sequences, so "a+b" stays "a+b". Use URLSearchParams, or replace + with a space before decoding when you know the text is form-encoded.

Is %20 ever wrong?

Practically never. Every form decoder also accepts %20 as a space. The only risk is a system that compares encoded strings byte for byte, such as some request signatures, where you must use exactly the encoding the specification asks for.

Should a file name with a space use + or %20?

%20. File names are in the path, where + stays a plus. A link to "Q3+report.pdf" asks for a file literally named with a plus sign.

See also

Try everything in this guide hands-on, free and entirely in your browser.

Decode + and %20 in the URL Decoder

Keep reading