What is URL encoding?+
URL encoding replaces unsafe characters with a % followed by two hexadecimal digits. For example, a space becomes %20, & becomes %26, and = becomes %3D.
When should I URL-encode my data?+
Always encode values being placed in URL query parameters. This prevents characters like &, =, and # from being interpreted as URL structure rather than data.
What is the difference between encodeURI and encodeURIComponent?+
encodeURI encodes a full URL but leaves reserved characters (like /, ?, &, =) intact. encodeURIComponent encodes everything including reserved characters - use it for individual query parameter values.
Why does a space become %20 in some places and + in others?+
%20 is the standard URL encoding for a space per RFC 3986. The + sign for spaces is an older convention from HTML form encoding (application/x-www-form-urlencoded) and should only be used in that context.
When do I need to URL-encode my data?+
Always URL-encode values placed in query string parameters. Characters like &, =, #, ?, and spaces have special meaning in URLs. Encoding them as percent sequences prevents the server from misinterpreting your data as URL structure.
What is percent encoding and how does it work?+
Percent encoding (also called URL encoding) replaces each unsafe byte with a percent sign followed by two uppercase hexadecimal digits representing the byte value. The space character (byte 0x20) becomes %20, the ampersand (byte 0x26) becomes %26, and so on.
How do I encode spaces in a URL?+
Use %20 in path segments and query parameter values per RFC 3986. The + character is also used to represent spaces in application/x-www-form-urlencoded query strings (as submitted by HTML forms). Most modern frameworks handle this automatically, but manual encoding should use %20.
What are double encoding pitfalls in URL encoding?+
Double encoding happens when an already-encoded URL is encoded again - turning %20 into %2520. This breaks the URL and causes 404 errors or malformed parameter values. Always decode before re-encoding, and never encode a complete URL - only encode the individual parameter values.