URL Encoding Spaces: %20 vs + (When to Use Which)
%20 is the standard RFC 3986 percent-encoding for a space character and should be used in URL paths and most contexts. The + sign represents a space only in application/x-www-form-urlencoded format, used in HTML form submissions and some query strings.
What Does %20 Mean?
%20 is the percent-encoded representation of the space character (ASCII code 32, hexadecimal 0x20) as defined by RFC 3986. It is the standard way to represent spaces in any part of a URI, including path segments, query strings, and fragment identifiers.
When you see %20 in a URL, it simply means "there is a space here." For example, https://example.com/my%20file.pdf refers to a resource named "my file.pdf". The %20 is universally understood by all web servers, browsers, and HTTP libraries.
What Does + Mean in a URL?
The + sign representing a space comes from the application/x-www-form-urlencoded content type, which was defined in the HTML specification for encoding form data. When an HTML form is submitted using the GET method, the browser encodes spaces as + in the resulting query string.
For example, if you type "hello world" into a search form and submit it, the browser generates a URL like https://example.com/search?q=hello+world. The+ here means "space," but only because the query string is using the form-urlencoded format.
It is important to note that + has no special meaning outside the application/x-www-form-urlencoded format. In a URL path like /files/my+file.pdf, the + is a literal plus sign, not a space. The file being referenced is literally named "my+file.pdf".
The Key Difference
The fundamental difference is the specification each belongs to. %20 is defined by RFC 3986 (URIs) and works everywhere in a URL. The +-as-space convention is defined by the HTML/WHATWG specification for form data and only works in query strings that are explicitly treated as form-urlencoded data.
%20works in paths, query strings, fragments, and all URI contexts+only means "space" inapplication/x-www-form-urlencodedquery strings- In URL paths,
+is a literal plus sign, not a space %20is always safe;+is context-dependent- If you encode a literal
+in form data, it becomes%2B
Which Should You Use?
Use %20 when building URLs programmatically, constructing REST API requests, encoding path segments, or whenever you are unsure. It is the universally correct encoding for spaces in URIs.
Use + only when you are intentionally producing application/x-www-form-urlencoded data, such as building query strings that mimic HTML form submissions, or when an API explicitly requires this format.
Most modern APIs and frameworks accept both %20 and + in query strings. However, using %20 is more portable and avoids ambiguity, especially when the query string might be used in contexts outside of form submissions.
How Different Languages Handle Spaces
Different programming languages and their standard libraries may default to either%20 or + for encoding spaces. Knowing the default behavior of your language helps you avoid surprises.
// JavaScript
encodeURIComponent('hello world'); // "hello%20world" (%20)
new URLSearchParams({q: 'hello world'}).toString(); // "q=hello+world" (+)
// To force %20 in query strings:
new URLSearchParams({q: 'hello world'}).toString().replace(/\+/g, '%20');# Python
from urllib.parse import quote, quote_plus, urlencode
quote('hello world', safe='') # "hello%20world" (%20)
quote_plus('hello world') # "hello+world" (+)
urlencode({'q': 'hello world'}) # "q=hello+world" (+ by default)
# To force %20:
urlencode({'q': 'hello world'}, quote_via=quote) # "q=hello%20world"// PHP
rawurlencode('hello world'); // "hello%20world" (%20)
urlencode('hello world'); // "hello+world" (+)
// rawurlencode follows RFC 3986
// urlencode follows application/x-www-form-urlencoded