How Is a Space Encoded in a URL?
A space in a URL becomes %20 (or + in application/x-www-form-urlencoded). The %20 form (RFC 3986) is the universal standard for URL paths and query strings. The + form is specific to HTML form submissions and query parameters in that encoding.
When to Use %20 vs +
| Context | Space Encoding | Example |
|---|---|---|
| URL path | %20 | /my%20file.html |
| Query string (RFC 3986) | %20 | ?q=hello%20world |
| HTML form data | + | ?q=hello+world |
Code Examples
JavaScript
encodeURIComponent('hello world');
// "hello%20world"
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'
Try It Yourself
Use our URL Encode & Decode tool to encode any string for use in URLs.
Frequently Asked Questions
Should I use %20 or + for spaces in URLs?
Use %20 in URL paths. The + encoding is only valid in query strings of form submissions. When in doubt, %20 is always safe.
How do I URL-encode a space in JavaScript?
Use encodeURIComponent(' ') which returns '%20'. For form data, URLSearchParams uses + for spaces.