
Alpine.js Has a Free API: Add Interactivity to HTML Without a Build Step
You don't need React for a dropdown menu. You don't need Vue for a tab component. You need Alpine.js. What Is Alpine.js? Alpine.js is a lightweight JavaScript framework for composing behavior directly in HTML. Think of it as Tailwind for JavaScript. <script defer src= "https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" ></script> <div x-data= "{ open: false }" > <button @ click= "open = !open" > Toggle </button> <div x-show= "open" x-transition > Hello! I'm a dropdown. </div> </div> That's a complete interactive component. No npm. No build. No bundler. Core Directives <!-- Reactive data --> <div x-data= "{ count: 0 }" > <span x-text= "count" ></span> <button @ click= "count++" > + </button> </div> <!-- Conditional rendering --> <div x-data= "{ show: false }" > <div x-show= "show" x-transition > Visible when show=true </div> <template x-if= "show" ><p> Rendered conditionally </p></template> </div> <!-- Loops --> <div x-data= "{ items: ['Apple', 'Banana', 'Cherry'] }" > <templa
Continue reading on Dev.to Webdev
Opens in a new tab



