HTML URL Encoding
HTML URL encoding is used to ensure that URLs are transmitted correctly over the internet by converting characters into a format that can be safely included in a URL. This encoding is particularly important for characters that might have special meanings in URLs or could be misinterpreted by web browsers or servers.
What is URL Encoding?
URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits representing the character’s ASCII code. This helps avoid issues with characters that might be misinterpreted, such as spaces or special symbols.
Common Characters and Their Encodings
- Space:
%20
- Exclamation mark (
!): %21
- Hash (
#): %23
- Dollar sign (
$): %24
- Percent sign (
%): %25
- Ampersand (
&): %26
- Single quote (
'): %27
- Left parenthesis (
(): %28
- Right parenthesis (
)): %29
- Asterisk (
*): %2A
- Plus sign (
+): %2B
- Comma (
,): %2C
- Slash (
/): %2F
- Colon (
:): %3A
- Semicolon (
;): %3B
- Less than (
<): %3C
- Equals (
=): %3D
- Greater than (
>): %3E
- Question mark (
?): %3F
- At sign (
@): %40
- Left bracket (
[): %5B
- Backslash (
\): %5C
- Right bracket (
]): %5D
- Caret (
^): %5E
- Underscore (
_): %5F
- Grave accent (
`): %60
- Left brace (
{): %7B
- Pipe (
|): %7C
- Right brace (
}): %7D
- Tilde (
~): %7E
Examples
-
Encoding a Space:
- Original URL:
https://example.com/search?query=hello world
- Encoded URL:
https://example.com/search?query=hello%20world
-
Encoding Special Characters:
- Original URL:
https://example.com/submit?name=John Doe&age=30
- Encoded URL:
https://example.com/submit?name=John%20Doe&age=30
-
Encoding a URL with Reserved Characters:
- Original URL:
https://example.com/path/to/page?name=John&age=30&city=New York
- Encoded URL:
https://example.com/path/to/page?name=John&age=30&city=New%20York
In these examples, spaces are replaced with %20, and other special characters are encoded accordingly to ensure that the URL is correctly interpreted by browsers and servers.