innerHTML

The DOM property that reads or replaces an element's contents as an HTML string, which the browser parses into nodes.

Assigning untrusted strings to innerHTML is a classic way to create cross-site scripting holes.

In more detail

It is convenient for building markup, but assigning untrusted text to innerHTML lets attackers inject elements that run script. Use textContent for text, and Trusted Types or sanitization when HTML is really needed.

Related terms

Taught in

References