Encoding
encoding
web
url
What is URL Encoding?
Definition
URL encoding (percent-encoding) replaces unsafe or reserved characters in a URL with a percent sign followed by two hexadecimal digits. For example, a space becomes %20 and an ampersand becomes %26.
Why It Matters
URLs can only contain a limited set of ASCII characters. URL encoding ensures special characters in query parameters, path segments, and form data are transmitted correctly without breaking the URL structure. Every web form submission uses URL encoding.
Code Example
from urllib.parse import quote, unquote
encoded = quote('hello world & more')
print(encoded) # hello%20world%20%26%20more
Language: python
Frequently Asked Questions
What is the difference between %20 and + for spaces?
In URL path segments, spaces are encoded as %20. In HTML form data (application/x-www-form-urlencoded), spaces are encoded as +. Both represent a space character.