How to Encode and Decode URLs: A Complete Developer Guide
URL encoding, officially known as percent-encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI) under certain circumstances.
Why Do We Need URL Encoding?
URLs can only be sent over the internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, they must be converted into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits representing the character's UTF-8 byte value.
Common Encoded Characters:
- Space
becomes%20(or+in some context) - Exclamation mark
!becomes%21 - Hash
#becomes%23 - Dollar
$becomes%24 - Ampersand
&becomes%26
URL Encoder / Decoder
Encode or decode URLs and URI query parameters online. Safely format special characters, spaces, and reserved symbols client-side with full UTF-8 support.
URL Decoding
URL decoding is the reverse process of encoding. It replaces percent-encoded sequences like %20 back into their corresponding characters (like spaces).
JavaScript Methods:
- Encoding:
encodeURIComponent("hello world!")->"hello%20world!" - Decoding:
decodeURIComponent("hello%20world!")->"hello world!"