--- name: alpine description: | Alpine.js is a lightweight JavaScript framework for adding interactivity to HTML markup. It provides reactive data, event handling, and DOM manipulation through HTML attributes — like a modern jQuery replacement with declarative syntax. license: Apache-2.0 compatibility: 'Alpine.js 3.17.x; any web server or bundler; modern browsers' metadata: author: terminal-skills version: 1.1.0 repository: https://github.com/alpinejs/alpine category: development tags: "javascript, html, lightweight, reactive" --- # Alpine.js ## Overview Alpine.js adds reactive behavior directly in HTML markup using `x-` attributes. It's ideal for adding interactivity to server-rendered pages without a build step or SPA framework. The current release is 3.17.5 (npm, October 2026); all snippets below were run against it in a DOM test. ## Instructions Load Alpine with `defer`, put `x-data` on the element that owns the state, and use directives (`x-show`, `x-text`, `x-model`, `x-for`, `@event`) inside it. Reusable logic goes into `Alpine.data()`, shared state into `Alpine.store()`. ## Installation ```html ``` ```javascript // main.js — npm module setup import Alpine from 'alpinejs'; window.Alpine = Alpine; Alpine.start(); // call once, after registering Alpine.data / Alpine.store / plugins ``` If the page runs under a strict Content-Security-Policy without `unsafe-eval`, use the `@alpinejs/csp` build, which does not use `eval`/`new Function` and so limits what inline expressions may contain. ## Core Directives ```html
This content can be toggled
Count:
Count is greater than 5!
Hello, !