What is URL encoding?
Also called percent-encoding: characters that are not allowed or have special meaning in a URL are replaced by % followed by two hex digits for each of their UTF-8 bytes. A space becomes %20 and é becomes %C3%A9.
How do I URL encode a space: %20 or +?
Use %20 in paths and whenever you follow RFC 3986. A + means space only in form-encoded query strings (application/x-www-form-urlencoded). Both decode to a space in a query string, but only %20 is safe everywhere.
Should I use encodeURI or encodeURIComponent?
encodeURIComponent for a single value inside a URL, encodeURI for a whole URL. When in doubt, build URLs with the URL and URLSearchParams APIs, which encode each part correctly for you.
Which characters need to be URL encoded?
Everything except letters, digits and - . _ ~ when it appears inside a value. Reserved characters such as / ? # & = + are left as they are only when they act as URL structure, and spaces, % and non-ASCII characters are always encoded.
Why does decoding fail with a malformed error?
A % must be followed by two hex digits that form valid UTF-8. A stray % or a truncated sequence such as %E0%A4 cannot be decoded. Encode a literal percent sign as %25.
What is double encoding and how do I fix it?
It is when encoded text is encoded again, turning %20 into %2520. Decode repeatedly until the text stops changing, then find the layer of code that encodes a second time and remove it.
Why does %2F stay encoded in Full URL mode?
Full URL mode uses decodeURI, which keeps escapes for structural characters such as %2F, %3F, %23 and %26, because decoding them would change the URL's meaning. Switch to Component mode to decode everything.
Is URL encoding the same as Base64 or encryption?
No. URL encoding only makes text safe to put in a URL and anyone can reverse it. Base64 turns bytes into text, and neither one hides or protects data; use encryption for that.
Does URL encoding prevent XSS or injection attacks?
Not on its own. It stops a value breaking the URL, but once the value is decoded and written into HTML or SQL it needs the right escaping or parameterised queries for that context.
Is my URL sent anywhere?
No. Encoding, decoding and parsing use your browser's built-in functions in this tab, so internal URLs, tokens and query strings stay on your device.