📝 Input
📤 Output
What Are HTML Entities?
HTML entities are special codes used to represent characters that have reserved meaning in HTML or that cannot be easily typed on a keyboard. When a browser encounters an HTML entity, it renders the corresponding character on screen. For example, the less-than sign (<) is written as < in HTML source code because the raw < character would be interpreted as the start of an HTML tag.
There are two forms of HTML entities: named entities (like & for &, © for ©) and numeric entities (like < for < or < using hexadecimal). Named entities are easier to read in source code, while numeric entities can represent any Unicode character.
Why HTML Encoding Matters for Security
Proper HTML encoding is one of the most critical defenses against Cross-Site Scripting (XSS) attacks. When user-generated content is displayed on a web page without encoding, an attacker can inject malicious JavaScript code through form inputs, URL parameters, or other user-controllable data. By encoding all output that originates from user input — converting characters like <, >, &, ", and ' to their HTML entity equivalents — you ensure that the browser treats the content as text rather than executable code.
Common HTML Entities Reference
The five most important characters to encode are: & (ampersand) → &, < (less than) → <, > (greater than) → >, " (double quote) → ", and ' (single quote) → '. These five characters are sufficient to prevent most HTML injection attacks when applied to content placed within HTML elements and attributes.