What is URL encoding?
URL encoding (percent encoding) replaces special characters with a % followed by two hexadecimal digits. Space becomes %20, & becomes %26, = becomes %3D.
When do I need to URL encode?
Encode URLs when they contain spaces or special characters that have meaning in URLs (?, &, =, #, %). Always encode query string values before appending to a URL.
What characters are safe in URLs?
The 'unreserved characters' that do not need encoding are: A–Z, a–z, 0–9, hyphen (-), underscore (_), period (.) and tilde (~). All other characters should be encoded.
What is the difference between encodeURI and encodeURIComponent in JavaScript?
encodeURI encodes a full URL but leaves /, ?, &, = and # intact. encodeURIComponent encodes everything including these characters — use it for individual query parameter values.