What Is URL Encoding?
URL encoding (also known as percent-encoding) is a mechanism for converting characters into a format that can be safely transmitted within a URL. Characters that have special meaning in URLs (such as &, =, ?, /) or non-ASCII characters are replaced with a % followed by their hexadecimal byte values.
URL encoding is defined in RFC 3986 and is essential for building valid URLs, especially when including user input in query parameters or path segments.
Example: The text hello world & more becomes hello%20world%20%26%20more when URL-encoded. Spaces become %20 and the ampersand becomes %26.
When to Use URL Encoding
- Query parameters — When including user input in URL query strings.
- Form data — HTML forms with
application/x-www-form-urlencodedencoding. - API requests — Constructing URLs with dynamic values for REST API calls.
- Internationalized URLs — Encoding non-ASCII characters (Unicode) in URLs.
- File paths in URLs — Encoding spaces and special characters in file names.
Characters That Need Encoding
- Reserved characters —
: / ? # [ ] @ ! $ & ' ( ) * + , ; = - Spaces — Encoded as
%20(or+in form data). - Non-ASCII characters — All Unicode characters outside the ASCII range.
- Unsafe characters —
< > { } | \ ^ ~ ` "
Frequently Asked Questions
What is the difference between %20 and + for spaces?
%20 is the standard percent-encoding for spaces (RFC 3986). The + encoding is specific to application/x-www-form-urlencoded format used by HTML forms. Our tool uses %20 for maximum compatibility.
Is URL encoding the same as HTML encoding?
No. URL encoding converts characters for safe use in URLs using percent notation. HTML encoding converts characters for safe display in HTML using entity notation (e.g., &). They serve different purposes.