Svelte and SvelteKit 5 · Template syntax
Toggle classes
Add a class conditionally with an object or array in the class attribute.
<div class={["card", { active: isActive, disabled }]}>...</div>
Official Svelte and SvelteKit 5 documentation
More template syntax commands
- Show content conditionally
- Loop over a list
- Show an async result
- Bind form inputs
- Handle events
- Reusable markup with snippets
All template syntax commands · Svelte and SvelteKit 5 cheatsheet