Event Handlers in Svelte

From the Svelte cheat sheet ยท Events & Actions ยท verified Jul 2026

Event Handlers

Handling DOM events in Svelte 5

javascript
<script>
  let count = $state(0);
  
  function handleClick() {
    count++;
  }
</script>

<button onclick={handleClick}>
  Count: {count}
</button>

<button onclick={() => count++}>
  Increment
</button>
๐ŸŽฏ Use onclick, onsubmit, etc. (lowercase) in Svelte 5
๐Ÿ“ Access event object in handler functions
๐Ÿ”„ No automatic preventDefault - must call manually
โšก Direct event binding for better performance

Continue with Svelte

Save the full cheat sheet or work through every related task.

More Svelte tasks

Back to the full Svelte cheat sheet