Web Dev Academy JavaScript frameworks · Alpine.js Tool 16 / 64
JavaScript frameworks

Alpine.js

Sprinkle reactivity right in your HTML. Alpine gives you the power of a reactive framework with a handful of attributes — no build step, no components, just markup.

Demo 01

x-data & x-show — a dropdown

x-data declares a scope of reactive state, and x-show toggles visibility. Click to open the menu — this is real, live Alpine.

<div x-data="{ open: false }">
  <button @click="open = !open">Menu ▾</button>
  <div x-show="open" @click.outside="open = false">
    …menu items…
  </div>
</div>
Demo 02

x-model — two-way binding

x-model binds an input to state. Type below and watch the live preview, all without leaving HTML.

Hi there, !

<div x-data="{ name: '' }">
  <input x-model="name">
  <p>Hi there, <b x-text="name || 'friend'"></b>!</p>
</div>
Demo 03

x-show toggle with transitions

Show and hide content with a smooth transition using x-show + x-transition.

Alpine reads these attributes after the page loads and wires up the reactivity for you. There is no compile step — drop the script tag in and it just works.
<button @click="open = !open">Toggle</button>
<div x-show="open" x-transition>…details…</div>
Demo 04

x-for — rendering a list

x-for (on a <template>) loops over an array. Add and remove tags in this live Alpine list.

<template x-for="(tag, i) in tags" :key="i">
  <li>
    <span x-text="tag"></span>
    <button @click="tags.splice(i, 1)">×</button>
  </li>
</template>
i
Built with real Alpine.js 3 loaded from CDN (cdn.min.js, deferred). Every demo above is genuine Alpine running directly off HTML attributes — x-data, x-show, x-model, x-for, x-text and x-transition — with no build step. The shared CSS shell provides page styling.

↑ All 64 tools