set:text
The set:text directive sets an element's text content with automatic HTML escaping.
Syntax
<span set:text={userInput} /> Examples
---
const userInput = '<script>alert(1)</script>';
---
<span set:text={userInput} />
Output
Renders the literal characters of the string as visible text; the script does not execute.
Notes
This is the safe choice for untrusted strings because special characters are escaped. Astro already escapes interpolated expressions by default, so set:text is mainly useful for dynamic tag patterns and parity with set:html.