Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Persists counter and theme state in localStorage.
<div x-data="{
count: parseInt(localStorage.getItem('count')) || 0,
isDark: localStorage.getItem('isDark') === 'true',
update() {
localStorage.setItem('count', this.count);
localStorage.setItem('isDark', this.isDark);
}
}" :class="isDark ? 'dark-theme' : 'light-theme'">
<h2>Counter: <span x-text="count"></span></h2>
<div>
<button @click="count++; update()">+</button>
<button @click="count--; update()">-</button>
<button @click="count=0; update()">Reset</button>
</div>
<button @click="isDark = !isDark; update()">Switch to <span x-text="isDark ? 'Light' : 'Dark'"></span> Theme</button>
</div>Alpine.js is a lightweight, declarative JavaScript framework that provides reactivity and interactivity directly in your HTML. It is often described as 'Tailwind for JavaScript' - offering the power of large frameworks with minimal overhead.
Origin & Creator
Created by Caleb Porzio and released in 2019 as part of the Laravel/Blade ecosystem, inspired by Vue.js reactivity but built for small, inline components.
Industrial Note
Alpine.js excels for micro-interactions, widgets, and progressive enhancement - especially in server-rendered environments like Laravel, Rails, Phoenix, and Django.