URL Encode Spaces — %20 vs +
Learn how spaces are encoded in URLs: when to use %20 and when to use +, and how to encode them correctly.
Open URL Encoder →%20 vs + for Spaces
A space cannot appear literally in a URL, so it is always encoded — but there are two encodings.
%20 is the percent-encoding defined by RFC 3986 and is valid anywhere in a URL: path, query, or fragment. The + sign means a space only inside application/x-www-form-urlencoded data — the format HTML forms submit and the format of most query strings. Outside that context a literal + means a real plus sign. When in doubt, use %20: every server and parser accepts it, while + is space only by the form-encoding convention.Which One Should You Use?
- Path segments: always
%20. A+in a path is a literal plus, not a space. - Query strings: both work;
+is conventional for form data,%20is always safe. - JavaScript:
encodeURIComponent(" ")gives%20. To produce form-style+, useURLSearchParamsor replace%20with+. - Java:
URLEncoder.encode()outputs+for spaces — replace with%20for use in a path. - Decoding: a
+only becomes a space if you decode it as form data;decodeURIComponentleaves+as-is.
// %20 everywhere (safe)
encodeURIComponent("hello world");
// "hello%20world"
// + for form/query data
new URLSearchParams({ q: "hello world" }).toString();
// "q=hello+world"
// Python
from urllib.parse import quote, quote_plus
quote("hello world") # "hello%20world"
quote_plus("hello world") # "hello+world"