What is HTML encoding
Converts characters with special meaning in HTML — like <, >, & and quotes — into entities (<, >, &) so they display as literal text instead of being interpreted as code.
When to use it
Essential for displaying source code inside a web page, or to prevent user-typed text from being interpreted as HTML/script (basic XSS prevention).
Input and output example
The text <script>alert(1)</script> becomes <script>alert(1)</script> and appears on the page as plain text instead of running. Double quotes become " and a single quote is often written '; both matter when the text lands inside an attribute such as value="...".
Why you see &amp; on the page
That means double encoding: the ampersand of an existing entity was encoded again. When encoding, the ampersand must be handled first; if it came last, the entities produced earlier would be corrupted.
Context matters
HTML entities suit element text and attribute values. Inside a script block, a URL or CSS, escaping follows different rules, so HTML encoding alone is not enough there.
The entity stands for a non-breaking space and © for the © symbol. Numeric entities work for any Unicode character.
Frequently asked questions
Why do I need to encode HTML?
To display characters like < and > as literal text instead of having the browser interpret them as part of the page's code.
Does this protect against XSS attacks?
It helps as a basic layer, but doesn't replace proper validation and sanitization on the backend.