What is URL encoding and why is it needed?
URLs were standardised in RFC 3986 with a restricted set of allowed characters: letters (A-Z, a-z), digits (0-9), and a handful of symbols (-, _, ., ~). All other characters, including spaces, non-ASCII Unicode, and characters that carry structural meaning in URLs (?, &, =, #, /), must be percent-encoded when used in contexts where they could be misinterpreted.
The encoding process is straightforward: take the UTF-8 byte representation of the character, then represent each byte as %XX where XX is the hexadecimal value. A space (UTF-8 0x20) becomes %20. The pound sign # (0x23) becomes %23. The full stop/period does not need encoding in most contexts, but parentheses (0x28 = %28, 0x29 = %29) do in strict implementations.
URL encoding matters in several practical web development scenarios. Query string parameters: if a user searches for "C&A fashion" on your site, the & in the query must be encoded as %26 otherwise it will be interpreted as a parameter separator, breaking the URL structure. Form submissions: HTML forms URL-encode field values before sending them in GET requests. Email links: mailto: URLs must encode spaces and line breaks in pre-filled body text.
JavaScript provides encodeURIComponent() for encoding individual query parameter values and encodeURI() for encoding a full URL while leaving structural characters (/, ?, &, #) intact. Knowing which to use prevents double-encoding bugs where an already-encoded %20 becomes %2520 because the percent sign itself gets encoded again.
A URL encoder/decoder tool is indispensable when constructing complex redirect rules, debugging tracking parameters, or decoding query strings from server logs.