Web browsers use reserved characters like
<,
>,
&, and
" to define tag structures and attributes. Displaying raw user input containing these characters directly in HTML causes tag parsing errors or introduces severe Cross-Site Scripting (XSS) security vulnerabilities. HTML entities convert reserved characters into safe character reference codes that browsers render as visible text without executing as HTML code.
<!-- Raw Text Input -->
<script>alert("XSS")</script>
<!-- HTML Entity Encoded Output -->
<script>alert("XSS")</script>