x-html Directive
Render raw HTML. Use with caution – only for trusted content!
What is x-html?
x-html sets the innerHTML of an element. It can render actual HTML tags but should only be used with trusted content to avoid XSS vulnerabilities.
When to Use
Only use x-html when you absolutely need to render HTML markup and you are sure the content is safe (e.g., static HTML from your own CMS). Never use it with unsanitized user input.
Example
Code
<div x-data="{ rawHtml: '<strong>Bold text</strong>' }">
<div x-html="rawHtml"></div>
<!-- Output: Bold text (rendered as bold) -->
</div>⚠️ Warning
Never use x-html with unsanitized user input – it can lead to severe XSS vulnerabilities. If you must display user content, sanitize it first with a library like DOMPurify.
Helpful? Share this page!↑ Back to top