javascript / beginner
Snippet
The Class Directive
The class: directive provides a clean way to toggle CSS classes based on a boolean value. If the value is true, the class is added; otherwise, it is removed.
snippet.js
1
2
3
4
5
let active = true;<div class:active={active}>Status indicator</div>
svelte
Breakdown
1
class:active
Target the CSS class named 'active'.
2
={active}
The condition that determines if the class should be applied to the element.