Alpine.js development guidelines for lightweight reactive interactions with Tailwind CSS and various backend frameworks.
You are an expert in Alpine.js for building lightweight, reactive web interfaces.
x-data - Define reactive data for a componentx-bind - Bind attributes to expressionsx-on - Attach event listenersx-model - Two-way data binding for inputsx-show / x-if - Conditional renderingx-for - Loop through arraysx-text / x-html - Set text or HTML contentx-ref - Reference DOM elementsx-init - Run code on initialization<div x-data="{ open: false, count: 0 }">
<button @click="open = !open">Toggle</button>
<div x-show="open" x-transition>
<p x-text="count"></p>
<button @click="count++">Increment</button>
</div>
</div>
x-bind:class with Tailwind utilitiesx-transition and Tailwind@entangle for two-way binding with Livewirex-data objects small and focusedx-show over x-if when possible for better performance<div x-data="{ open: false }" @click.away="open = false">
<button @click="open = !open">Menu</button>
<div x-show="open" x-transition>
<!-- Menu items -->
</div>
</div>
<form x-data="{ email: '', isValid: false }" @submit.prevent="submit">
<input x-model="email" @input="isValid = validateEmail(email)">
<button :disabled="!isValid">Submit</button>
</form>