Svelte and SvelteKit 5 · Template syntax
Handle events
Events are properties like onclick. Call preventDefault yourself when needed.
<button onclick={save}>Save</button>
<form onsubmit={(e) => { e.preventDefault(); submit(); }}>...</form>
Official Svelte and SvelteKit 5 documentation
More template syntax commands
- Show content conditionally
- Loop over a list
- Show an async result
- Bind form inputs
- Toggle classes
- Reusable markup with snippets
All template syntax commands · Svelte and SvelteKit 5 cheatsheet