When to use &, < and Unicode escapes in HTML
By TechCompare · Updated · How we check
Always entity-encode user-supplied text in HTML. Let your framework do it automatically. Only use named/numeric entities for literal characters you're writing yourself in static HTML. For emoji and non-ASCII text, use UTF-8 directly rather than numeric entities.
HTML entity encoding replaces characters that have special meaning in HTML with named or numeric entities: < becomes <, > becomes >, & becomes &, and double-quote becomes ". This is a security requirement, not a style choice. Without it, user-supplied text containing <script> tags will execute in the browser.
How this is calculated
The five characters that must always be entity-encoded in HTML text content are ampersand, less-than, greater-than, single-quote, and double-quote. Modern frameworks (React, Vue, Svelte) do this automatically when you use their templating syntax. The risk surfaces when you use dangerouslySetInnerHTML, innerHTML in vanilla JS, or server-side template engines that don't auto-escape.
Verdict
Let your framework entity-encode the five characters that gate the XSS surface: ampersand, less-than, greater-than, single-quote, and double-quote. The risk only surfaces with dangerouslySetInnerHTML, raw innerHTML, or non-escaping server engines. For non-ASCII characters including emoji, declare <meta charset='utf-8'> and ship them directly instead of leaning on numeric entities like 😀.
More Encoding scenarios
Related guides
Frequently asked questions
Which characters must be entity-encoded in HTML?
Does React escape HTML entities automatically?
Should I use HTML entities for emoji and accent characters?
Related tools
JSON Formatter
Validate, format, and minify JSON. Browse it as a tree, run JSONPath queries, compare two documents, or validate against a JSON Schema.
Use toolUnix Timestamp
Convert between Unix timestamps and human-readable dates.
Use toolCron Generator
Visually build standard 5-part cron expressions or translate them into readable schedules.
Use tool