Why URLs Require Encoding
Uniform Resource Locators (URLs) are restricted to a limited subset of US-ASCII characters. Characters like spaces, ampersands (&), question marks (?), and equals signs (=) serve reserved structural purposes in HTTP query strings. If user input contains these characters without escaping, browser and server parsers misinterpret the parameters.
const query = "shoes & socks/red";
// ❌ encodeURI keeps slashes and ampersands intact:
console.log(encodeURI(query));
// Output: "shoes%20&%20socks/red" (Breaks query parameter parsing!)
// ✅ encodeURIComponent escapes ALL reserved delimiters:
console.log(encodeURIComponent(query));
// Output: "shoes%20%26%20socks%2Fred" (Safe for query values!)
Encode or Decode URLs Instantly
Safely encode query parameters or decode percent-encoded URLs and form bodies.
Frequently Asked Questions
%20 for standard percent-encoding across all URI parts. The + symbol is an older convention defined for HTML form submissions (application/x-www-form-urlencoded) inside query strings. Both are widely supported by servers.%) is encoded again into %25. For example, %20 becomes %2520, causing search queries and file paths to resolve incorrectly.