It allows you to insert raw HTML code directly into your component's output, rendering it as HTML instead of plain text.
Click to reveal answer
intermediate
Why should you be careful when using {@html} with user input?
Because it can lead to security risks like Cross-Site Scripting (XSS) if the HTML is not sanitized before rendering.
Click to reveal answer
beginner
How do you use {@html} to render a variable containing HTML in Svelte?
Use it inside curly braces like this: {@html variableName}, where variableName holds the HTML string.
Click to reveal answer
intermediate
Can {@html} render scripts or styles inside the HTML string?
Scripts inside {@html} are inserted but may not execute as expected. Styles will apply if valid. It's best to avoid scripts for security and behavior reasons.
Click to reveal answer
intermediate
What is a safer alternative to {@html} when displaying user content?
Sanitize the HTML string before using {@html} or use plain text rendering to avoid injecting unsafe HTML.
Click to reveal answer
What does {@html} do in Svelte?
AEscapes HTML tags to show as text
BCreates a new HTML element
CImports external HTML files
DRenders a string as raw HTML inside the component
✗ Incorrect
The {@html} tag renders the string as raw HTML inside the component.
Which risk is most associated with using {@html} on unsanitized user input?
ACross-Site Scripting (XSS)
BMemory leak
CSlow rendering
DCSS conflicts
✗ Incorrect
Unsanitized HTML can allow malicious scripts, causing XSS attacks.
How do you insert a variable named 'content' as HTML using {@html}?
A<html>{content}</html>
B{content}
C{@html content}
D<div>{@html content}</div>
✗ Incorrect
Use {@html content} to render the variable as HTML.
What happens if you put a <script> tag inside {@html} content?
AThe script is converted to plain text
BThe script may not run as expected and can cause security issues
CThe script is automatically removed
DThe script runs normally without issues
✗ Incorrect
Scripts inside {@html} may not execute properly and pose security risks.
What is the best practice before using {@html} with dynamic content?