Home/Glossary/HTML Entity Encoding

HTML Entity Encoding

A method of representing special characters in HTML using named or numeric references to prevent interpretation as code.

Web SecurityAlso called: "html entities", "html escaping"

HTML encoding converts special characters into entities to display them safely.

Common entities

  • < : < (less than).
  • > : > (greater than).
  • & : & (ampersand).
  • " : " (quote).
  • ' : ' (apostrophe).
  •   : Non-breaking space.

Why encode?

  • Prevent browsers from interpreting characters as HTML tags.
  • Display reserved characters literally.
  • Prevent cross-site scripting (XSS) attacks.
  • Properly render special and international characters.

Numeric encoding

  • Decimal: < (< symbol).
  • Hexadecimal: < (< symbol).

Security use

  • Essential for preventing XSS when displaying user input.
  • Encode all untrusted data before inserting into HTML.