AnatomyOf

Anatomy of a Svelte file

example.svelte
1<script>
2 // The component's entire brain. Yes, that is all of it.
3 let count = $state(0)
4</script>
5
6<button onclick={() => count++}>
7 clicked {count} times
8</button>
9
10<style>
11 button {
12 cursor: pointer;
13 }
14</style>
Svelte is a compiler, not a runtime framework: a .svelte file is a single component (script, markup, and styles together) that compiles to plain JavaScript which updates the DOM directly, so no framework library ships to the browser.