Encode and decode URLs with percent-encoding. Handles special characters, query strings, and Unicode.
URL encoding converts special characters to percent-encoded format (%XX) where XX is the hexadecimal representation of the character. This ensures URLs are valid and can be safely transmitted over the internet.
encodeURI: Encodes a full URI. Does NOT encode: : / ? # [ ] @ ! $ & ' ( ) * + , ; =. Use for encoding complete URLs.
encodeURIComponent: Encodes a URI component (like a query parameter value). Encodes ALL special characters except: - _ . ! ~ * ' ( ). Use for encoding individual parameter values.
| Character | Encoded | Description |
|---|---|---|
| Space | %20 or + | Space character |
| ! | %21 | Exclamation mark |
| # | %23 | Hash/pound |
| $ | %24 | Dollar sign |
| & | %26 | Ampersand |
| + | %2B | Plus sign |
| / | %2F | Forward slash |
| = | %3D | Equals sign |
| ? | %3F | Question mark |
| @ | %40 | At sign |