javascript / beginner
Snippet
Rendering Raw HTML with {@html}
By default, Svelte escapes HTML tags for safety. The {@html} tag allows you to render strings as actual HTML elements inside the component.
snippet.js
1
2
3
4
5
<script>let content = '<strong>Warning:</strong> Use with care!';</script><div>{@html content}</div>
svelte
Breakdown
1
{@html content}
Directs Svelte to inject the string as raw HTML rather than plain text.