Components for Alpine.js
Define reusable template components in their own files and render them anywhere with a single directive — no build step required.
// Define your component once export default { template: ` <div x-data="__self__"> <p>Count: <span x-text="count"></span></p> <button @click="increment">+</button> </div> `, data: () => ({ count: 0, increment() { this.count++ } }) }
<!-- Use it anywhere --> <div x-component="'Counter'"></div>
x-component
Render any component inline by name
Isolated state
Each component manages its own Alpine data
No build step
Works with CDN or any Alpine.js setup