Encode or decode URLs and special characters.
URL encoding (percent-encoding) converts characters into a format that can be transmitted over the Internet. URLs can only contain ASCII characters, so special characters, spaces, and Unicode must be encoded using % followed by hex values.
| Character | Encoded | Description |
|---|---|---|
| (space) | %20 | Space character |
| ! | %21 | Exclamation mark |
| # | %23 | Hash/pound |
| $ | %24 | Dollar sign |
| & | %26 | Ampersand |
| + | %2B | Plus sign |
| = | %3D | Equals sign |
| @ | %40 | At sign |
encodeURIComponent encodes everything except: A-Z a-z 0-9 - _ . ! ~ * ' ( ). Use this for query parameter values.
encodeURI preserves URL structure characters like : / ? # [ ] @ ! $ & ' ( ) * + , ; =. Use this for encoding a complete URL.