flashman
← All guides

HTML entities: encode text for safe markup

Escape &, <, >, and quotes to prevent XSS and fix broken HTML snippets.

2026-06-07 · 4 min read

  • html
  • security

HTML reserves characters like < and &. User-generated text must be entity-encoded before insertion into templates, or browsers may interpret input as markup—a classic cross-site scripting vector.

Characters to encode

Encode at output time in your templating layer, not only at input storage.

  • & → &amp;
  • < → &lt;
  • > → &gt;
  • " → &quot; in attributes

Named vs numeric entities

Named entities (&copy;) are readable; numeric (&#169;) work for arbitrary Unicode. Decoding entities helps when scraping or migrating CMS content.

Try these tools