EN
HTML - characters that should be escaped
10 points
In this short article, we would like to count what characters should be escaped in HTML.
Quick solution:
xxxxxxxxxx
1
REPLACED ALWAYS:
2
3
& should be replaced with &
4
< should be replaced with <
5
> should be replaced with >
6
7
8
REPLACED CONDITIONALLY in element attribute (depending on the case):
9
10
" should be replaced with " e.g. <div attribute="abc " abc"></div>
11
' should be replaced with ' e.g. <div attribute='abc ' abc'></div>
Character | HTML escape code | Description |
& | & | It is required to escape this character because it is used as an escape character, e.g. < , > , " , ' , etc. |
< | < | Opens HTML elements. |
> | > | Closes HTML elements. |
Additionally, inside of attribute values, it is necessary to escape the quote character:
Character | HTML escape code | Description |
" | " |
Needed only when xxxxxxxxxx 1 <p title=""John" life story ..."> 2 Few words about John life story... 3 </p> |
' | ' |
Needed only when xxxxxxxxxx 1 <a href='https://john.com' title='John's site'> 2 Home 3 </a>
|
xxxxxxxxxx
1
2
<html>
3
<body>
4
<p title=""John" life story ...">Few words about John life story...</p>
5
<a href='https://john.com' title='John's site'>Home</a>
6
<p>Source code should be placed between <code> and </code>.</p>
7
</body>
8
</html>