Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Demonstrates a simple counter component using Svelte reactive variables and event handling.
<script>
let count = 0;
let isDark = false;
function increment() { count += 1; }
function decrement() { count -= 1; }
function reset() { count = 0; }
function toggleTheme() { isDark = !isDark; }
</script>
<div class={isDark ? 'dark-theme' : 'light-theme'}>
<h2>Counter: {count}</h2>
<div>
<button on:click={increment}>+</button>
<button on:click={decrement}>-</button>
<button on:click={reset}>Reset</button>
</div>
<button on:click={toggleTheme}>Switch to {isDark ? 'Light' : 'Dark'} Theme</button>
</div>
<style>
.dark-theme { background-color: #222; color: #eee; }
.light-theme { background-color: #fff; color: #000; }
</style>Svelte is a modern, component-based JavaScript framework that shifts work from the browser to the build step. Instead of using a virtual DOM, Svelte compiles components into highly optimized vanilla JavaScript, delivering faster performance and smaller bundles.
Origin & Creator
Created in 2016 by Rich Harris, a graphics editor at The Guardian, aiming to simplify reactive UI development.
Industrial Note
Svelte is highly suited for performance-sensitive web apps, small-to-medium SPAs, interactive widgets, and animation-heavy projects.