Challenge - 5 Problems
HTML Rendering Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Svelte component render?
Consider this Svelte code snippet:
What will be the visible output in the browser?
<script>
let content = '<strong>Hello</strong> World!';
</script>
<p>{@html content}</p>What will be the visible output in the browser?
Svelte
<script> let content = '<strong>Hello</strong> World!'; </script> <p>{@html content}</p>
Attempts:
2 left
💡 Hint
Remember that {@html} inserts raw HTML, not escaped text.
✗ Incorrect
The {@html} tag in Svelte inserts the string as HTML, so the <strong> tags make 'Hello' bold. The rest is normal text.
📝 Syntax
intermediate1:30remaining
Which option correctly uses {@html} in Svelte?
You want to render a variable named 'htmlString' as raw HTML inside a div. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check the exact syntax for {@html} in Svelte.
✗ Incorrect
The correct syntax is {@html variableName} without parentheses or colons.
🔧 Debug
advanced2:00remaining
Why does this Svelte code not render HTML tags correctly?
Given this code:
Why does the browser show the tags as text instead of formatting?
<script>
let text = '<em>Italic</em> text';
</script>
<p>{text}</p>Why does the browser show the tags as text instead of formatting?
Svelte
<script> let text = '<em>Italic</em> text'; </script> <p>{text}</p>
Attempts:
2 left
💡 Hint
Think about how Svelte treats variables inside curly braces.
✗ Incorrect
Svelte escapes HTML inside variables by default to prevent XSS. To render raw HTML, {@html} must be used.
❓ state_output
advanced2:30remaining
What happens when the HTML string changes dynamically?
In this Svelte component:
What will the user see after clicking the button?
<script>
let htmlContent = '<span>First</span>';
function update() {
htmlContent = '<span style="color:red">Updated</span>';
}
</script>
<div>{@html htmlContent}</div>
<button on:click={update}>Change</button>What will the user see after clicking the button?
Svelte
<script> let htmlContent = '<span>First</span>'; function update() { htmlContent = '<span style="color:red">Updated</span>'; } </script> <div>{@html htmlContent}</div> <button on:click={update}>Change</button>
Attempts:
2 left
💡 Hint
Svelte updates the DOM when reactive variables change.
✗ Incorrect
When the variable changes, Svelte re-renders the {@html} block with the new HTML, showing 'Updated' in red.
🧠 Conceptual
expert1:30remaining
What is a key risk of using {@html} in Svelte?
Why should you be careful when rendering user-generated content with {@html} in Svelte?
Attempts:
2 left
💡 Hint
Think about security risks when inserting raw HTML.
✗ Incorrect
Using {@html} inserts raw HTML, so if the content is from users and not cleaned, malicious scripts can run.