What characters must be HTML-encoded to prevent XSS?
In HTML text and attribute values, encode at minimum: ampersand (& → &), less-than (< → <), greater-than (> → >), double quote (" → "), and single quote (' → ' or ') in attributes delimited by single quotes. Encoding & first prevents double-expansion when other entities are present. This neutralizes <script> and event-handler injection when output is inserted into HTML—not into script, style, or URL contexts.