Percent-encode and decode URL components.
URL encoding (percent-encoding) replaces unsafe characters in a URL with a % followed by hex digits, so query strings and parameters transmit correctly. Use Encode before putting text into a URL, and Decode to read an encoded URL. Runs entirely in your browser.
URL encoding (percent-encoding) replaces unsafe ASCII characters with % followed by two hexadecimal digits. Characters like spaces become %20 (or + in form data), & becomes %26, and = becomes %3D. Unreserved characters (A-Z, a-z, 0-9, -, _, ., ~) are not encoded. This ensures URLs contain only safe ASCII characters and special characters do not break URL parsing.
Whenever you put user text, spaces or special characters into a query string or path so the URL stays valid.
URL encoding keeps text readable and only escapes unsafe characters; Base64 turns everything into an ASCII blob. They solve different problems.
encodeURI preserves URL structure characters like : / ? # & =, while encodeURIComponent encodes everything except unreserved characters. Use encodeURIComponent for individual parameter values.
In URL paths and query strings, spaces should be %20. The + is only valid in application/x-www-form-urlencoded form data (POST bodies).