


We use cookies to improve your experience
We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience.
Definition
URL encoding (percent-encoding) replaces unsafe characters in URLs with a % followed by two hexadecimal digits. Spaces become %20, & becomes %26, and non-ASCII characters are encoded as UTF-8 byte sequences. This ensures URLs contain only valid ASCII characters.
URLs can only contain a limited set of ASCII characters. The RFC 3986 standard defines unreserved characters (A-Z, a-z, 0-9, -, _, ., ~) that can appear directly in URLs, and reserved characters (: / ? # [ ] @ ! $ & ' ( ) * + , ; =) that have special meaning in URL syntax. Any other character — including spaces, non-ASCII characters, and reserved characters used as data — must be percent-encoded.
Percent-encoding converts each byte of the character's UTF-8 representation to %XX format. A space (0x20) becomes %20. The euro sign (U+20AC, encoded as 0xE2 0x82 0xAC in UTF-8) becomes %E2%82%AC. The + character is sometimes used as an alternative encoding for spaces in query strings (application/x-www-form-urlencoded format), but %20 is the universal standard.
URL encoding is essential for building URLs with user-supplied data: search queries, form submissions, API parameters, and any dynamic URL components. JavaScript provides encodeURIComponent() for encoding individual URL components and encodeURI() for encoding complete URIs (which preserves reserved characters that are part of URL structure). Incorrect encoding is a common source of bugs in web applications.