javascript / beginner
Snippet
Rendering Raw HTML
By default, Svelte escapes HTML tags for security. If you need to render actual HTML from a string, use the @html tag, but be careful of Cross-Site Scripting (XSS).
snippet.js
1
2
3
4
5
<script>let message = 'Welcome to <b>Svelte</b>';</script><p>{@html message}</p>
svelte
Breakdown
1
let message = '...';
Defines a string variable containing HTML markup.
2
{@html message}
Special Svelte tag that renders the string as actual HTML elements instead of plain text.