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 | + |
|---|---|---|
| Path | A space | A literal plus sign |
| Query, read as form data (most frameworks) | A space | A space |
| Query, read with plain percent-decoding | A space | A literal plus sign |
| Fragment (after #) | A space | A 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.
| Language | Function | Space becomes |
|---|---|---|
| JavaScript | encodeURIComponent | %20 |
| JavaScript | encodeURI | %20 |
| JavaScript | URLSearchParams | + |
| JavaScript | escape (deprecated) | %20 |
| Python | quote (default safe='/') | %20 |
| Python | quote (safe='') | %20 |
| Python | quote_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:
| Language | Function | Result | Source |
|---|---|---|---|
| JavaScript | decodeURIComponent | "a+b c" | Run |
| JavaScript | URLSearchParams.get | "a b c" | Run |
| Python | urllib.parse.unquote | "a+b c" | Run |
| Python | urllib.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 |
| PHP | rawurldecode | "a+b c" | Documented |
| PHP | urldecode | "a b c" | Documented |
| Java | URLDecoder.decode | "a b c" | Documented |
| Go | url.PathUnescape | "a+b c" | Documented |
| Go | url.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%20bBoth 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'})givesq=a+b%2Bc. Passquote_via=quoteto getq=a%20b%2Bc.parse_qsdecodes+as a space;unquotedoes not,unquote_plusdoes. - PHP:
urlencodewrites+,rawurlencodewrites%20. The matching decoders areurldecodeandrawurldecode. - C#:
Uri.EscapeDataStringwrites%20;WebUtility.UrlEncodewrites+. On the way back,Uri.UnescapeDataStringkeeps+andWebUtility.UrlDecodeturns it into a space.
Which should you use?
- Writing URLs: use
%20unless you are reproducing an HTML form submission. It means a space everywhere, to every decoder. - Writing query values that may contain +: always encode the plus as
%2B. Component encoders do this for you. - Reading a query string: use a query parser (
URLSearchParams,parse_qs, your framework's request object), which treats+as a space as browsers expect. - Reading a path: use plain percent-decoding, which keeps
+. - Signing requests: follow the specification exactly. Signature schemes compare encoded bytes, so
+and%20are 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.