What Is URL Encoding (Percent-Encoding)?
URL encoding, formally known as percent-encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI). It replaces unsafe ASCII characters with a '%' sign followed by two hexadecimal digits, and non-ASCII characters with their UTF-8 byte sequences, each byte percent-encoded.
This encoding is defined in RFC 3986 and is essential for the correct functioning of the web. Without it, characters like spaces, ampersands, and question marks in data values would be confused with the URL's structural delimiters.
How URL Encoding Works
URLs only allow a specific set of unreserved characters: A-Z, a-z, 0-9, hyphen (-), underscore (_), period (.), and tilde (~). All other characters must be percent-encoded.
The encoding process converts each byte of a character to '%' followed by its hexadecimal value. For ASCII characters, this is straightforward: a space (byte 0x20) becomes '%20'. For Unicode characters, the text is first encoded as UTF-8, then each byte is percent-encoded: the emoji '☺' (U+263A) encoded as UTF-8 is the bytes E2 98 BA, which becomes '%E2%98%BA'.
Common URL Encoding Examples
Space → %20 (or + in form submissions) Ampersand (&) → %26 Equals (=) → %3D Question mark (?) → %3F Hash (#) → %23 Slash (/) → %2F At sign (@) → %40 Plus (+) → %2B Percent (%) → %25
Note: The '+' character for spaces is specific to 'application/x-www-form-urlencoded' format (HTML form submissions). In standard URLs, spaces should be encoded as '%20'. This tool uses the standard %20 encoding.
URL Encoding in Web Development
In JavaScript, use encodeURIComponent() to encode query parameter values and decodeURIComponent() to decode them. In Python, use urllib.parse.quote() and urllib.parse.unquote(). In PHP, use urlencode() and urldecode().
Most modern HTTP libraries and frameworks handle URL encoding automatically when building requests. However, understanding how it works is essential for debugging issues with special characters in URLs, API calls, and form submissions.
Frequently Asked Questions
Related Tools
Explore More Tools
Find this tool useful? Buy us a coffee to keep DuskTools free and ad-light.