✳️ 581+ Pro Blocks, lifetime updates, unlimited projects — Get 50+ fresh blocks every month ✳️ 👇
Grab the deal →

Tailwind Alpine.js Templates

Discover our collection of Alpine.js templates to build lightweight, reactive web interfaces effortlessly. Choose from premium and free options designed for developers.

Explore all
Popular products
BadtzUI Pro

Prebuilt templates & blocks for React and Next.js

Templates

Brutalism

Create bold, brutalist dashboards

HireWise

Colorful Astro job board template with 80+ components

BadtzUI Pro

Prebuilt templates & blocks for React and Next.js

JetShip

The Ultimate Laravel Starterkit for SaaS devleopers.

Taildash

Developer-friendly dashboard template

Flow

Flow

Paid

293 component SaaS template with Alpine.js support

Vista

Vista

Paid

Modern Tailwind SaaS template with 306 UI elements

Neudash

Neumorphism style admin template

Zinq

Zinq

Free

Laravel Livewire UI Toolkit

Consulty

Tailwind template for consulting sites

Futurism

sci-fi themed dashboard template

Simple

Simple

Paid

Clean, minimal Tailwind website template

Filytreck

110 responsive Tailwind UI components

Flabbergasted

44+ page neo brutalist landing page template built with Astro and Tailwind CSS

Outkast

43-Page Astro template with MDX blog

StudioMax

39 pages & 100+ sections for agencies

Kotei

Kotei

Paid

Swiss-inspired Astro theme with 100+ Tailwind components

Enlightr

57 page Tailwind e-learning template built with Astro

Carbon

Carbon

Paid

Bold dark directory theme

Alfred

Alfred

Paid

40+ pages and 100+ components SaaS template

Talent

Talent

Paid

Multi-page SaaS and hiring platform landing page

Quartiere

Quartiere: 48-page real estate theme

Riflesso

Minimalist template for agencies and portfolios

Vanta

Vanta

Paid

44-page modern theme for online courses

Snow

Snow

Paid

Tailwind admin template w/ Alpine.js

SuperStore

24+ page marketplace template built with AstroJS and Tailwind CSS

Carriera

Minimal Astro & Tailwind template

Community

Responsive Tailwind forum template

Docs

Docs

Paid

Customizable Tailwind CSS documentation kit

FinTech

Next.js & Tailwind CSS landing page for finance apps.

Podcast

Tailwind podcast template with built-in audio player

DevSpace

Modern Tailwind CSS blog template for developers

Streamer

Responsive one-page streaming site template

Author

Author

Paid

20 pages & 60+ Tailwind components for bloggers

Aubegine

20-page Astro template for agencies

Hemingway

25-page Astro blog template with search

Flaco

Flaco

Paid

Sleek Astro & Tailwind CSS portfolio theme

Buio

Buio

Paid

Blue-lit dark SaaS template built with Astro

Phanatik

42 page minimal blog template

Brightlight

Astro + Tailwind SaaS template with 30+ ready pages

ProFolioX

Modern, responsive Astro portfolio theme

Navy

Navy

Paid

40 page dark mode Astro template

Semplice

Modern multipage theme for tech startups

Cube

Cube

Paid

Modern Tailwind landing page template

Neon

Neon

Paid

Modern dark-themed landing page template

Creative

Tailwind template for creative communities

Appy

Appy

Paid

Tailwind template for mobile apps

Tidy

Tidy

Paid

12-page corporate website template

Open PRO

12 page Sleek SaaS template for startups

JobBoard

Tailwind CSS job board template

Saas UI

90+ Tailwind CSS components for SaaS landing pages

DuskUI

DuskUI

Paid

90 dark-mode components

Alpine.js is a lightweight JavaScript framework designed for adding interactivity to your HTML markup with minimal effort. It offers a declarative syntax similar to frameworks like Vue.js and React but is much simpler and ideal for enhancing static pages. Alpine.js Templates refer to the HTML structures enhanced with Alpine's directives to create dynamic, reactive, and interactive user interfaces.

Introduction to Alpine.js

Alpine.js is often described as "Tailwind for JavaScript" because it provides the power of JavaScript without the complexity of larger frameworks. It's particularly useful for adding interactivity to server-rendered HTML where full-fledged frameworks might be overkill.

Key Features:

  • Minimalistic: Small footprint (~10kB minified).

  • Declarative Syntax: Uses directives directly in HTML.

  • Reactivity: Supports reactive data binding.

  • Component-Based: Enables encapsulation of interactive parts.

Getting Started

To start using Alpine.js, include it via a <script> tag in your HTML. You can use a CDN for quick setup:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Alpine.js Example</title>
    <!-- Include Alpine.js from CDN -->
    <script src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js>" defer></script>
</head>
<body>
    <!-- Alpine.js code will go here -->
</body>
</html>

Note: The defer attribute ensures that Alpine.js initializes after the HTML is parsed.

Core Concepts and Directives

Alpine.js uses a declarative approach with various directives to manage state and behavior. Some of the core directives include:

  • x-data: Defines a component's reactive state.

  • x-bind: Binds HTML attributes to JavaScript expressions.

  • x-model: Creates two-way data bindings on form inputs.

  • x-on: Attaches event listeners.

  • x-if, x-show: Conditional rendering.

  • x-for: Looping over lists.

  • x-text, x-html: Updates text or HTML content.

Example of x-data and x-text

<div x-data="{ message: 'Hello, Alpine!' }">
    <span x-text="message"></span>
</div>

This initializes a component with a message property and binds its value to the <span> element.

Using Alpine.js Templates

Alpine.js templates leverage HTML enhanced with Alpine's directives to define interactive components. These templates can include state management, event handling, conditional rendering, and more—all within your HTML.

Basic Syntax

<div x-data="{ /* state */ }" x-init="/* initialization */">
    <!-- HTML content with Alpine directives -->
</div>
  • x-data: Initializes the component's state.

  • x-init: Runs JavaScript when the component is initialized.

Structuring Templates

Organize your templates by wrapping interactive parts in containers with x-data. Inside these containers, use Alpine directives to control behavior.

<div x-data="{ open: false }">
    <button @click="open = !open">Toggle</button>
    <div x-show="open">
        <p>This content is toggled.</p>
    </div>
</div>

Here, clicking the button toggles the visibility of the <div> containing the paragraph.

Examples

Let's explore more detailed examples to illustrate how Alpine.js templates work.

1. Toggle Visibility

A common use case is toggling the visibility of elements, such as showing and hiding sections or modals.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Toggle Example</title>
    <script src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js>" defer></script>
</head>
<body>
    <div x-data="{ open: false }" class="p-4">
        <button @click="open = !open" class="px-4 py-2 bg-blue-500 text-white rounded">
            Toggle Content
        </button>

        <div x-show="open" class="mt-4 p-4 border rounded">
            <p>Here is some toggled content!</p>
        </div>
    </div>
</body>
</html>

Explanation:

  • x-data="{ open: false }" initializes the open state.

  • @click="open = !open" toggles the open state when the button is clicked.

  • x-show="open" conditionally displays the content based on the open state.

2. Handling Forms

Alpine.js makes handling form inputs straightforward with x-model for two-way data binding.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Form Example</title>
    <script src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js>" defer></script>
</head>
<body>
    <div x-data="{ name: '', email: '' }" class="p-4">
        <form @submit.prevent="alert(`Name: ${name}, Email: ${email}`)" class="space-y-4">
            <div>
                <label class="block">Name:</label>
                <input type="text" x-model="name" class="border px-2 py-1"/>
            </div>
            <div>
                <label class="block">Email:</label>
                <input type="email" x-model="email" class="border px-2 py-1"/>
            </div>
            <button type="submit" class="px-4 py-2 bg-green-500 text-white rounded">Submit</button>
        </form>
    </div>
</body>
</html>

Explanation:

  • x-model binds the input values to the component's state (name and email).

  • The form's @submit.prevent prevents the default submission and triggers an alert with the input values.

3. Dynamic Lists

Rendering lists dynamically using x-for allows you to iterate over arrays and display items accordingly.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>List Example</title>
    <script src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js>" defer></script>
</head>
<body>
    <div x-data="{ items: ['Apple', 'Banana', 'Cherry'], newItem: '' }" class="p-4">
        <form @submit.prevent="if(newItem) { items.push(newItem); newItem = '' }" class="flex space-x-2">
            <input type="text" x-model="newItem" placeholder="Add new item" class="border px-2 py-1 flex-1"/>
            <button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded">Add</button>
        </form>

        <ul class="mt-4">
            <template x-for="(item, index) in items" :key="index">
                <li class="flex justify-between items-center p-2 border-b">
                    <span x-text="item"></span>
                    <button @click="items.splice(index, 1)" class="text-red-500">Delete</button>
                </li>
            </template>
        </ul>
    </div>
</body>
</html>

Explanation:

  • x-for iterates over the items array, rendering each as a list item.

  • x-model="newItem" binds the input to the newItem state.

  • Submitting the form adds newItem to the items array.

  • The delete button removes the corresponding item from the array.

Best Practices

  1. Keep It Simple: Use Alpine.js for enhancing static HTML. For complex applications, consider more robust frameworks.

  2. Encapsulate Components: Break down your UI into reusable Alpine components using x-data.

  3. Leverage Tailwind CSS: Alpine.js pairs exceptionally well with Tailwind CSS for styling.

  4. Avoid Global State: Keep state scoped within components to prevent unintended side effects.

  5. Use x-ref When Needed: For referencing DOM elements directly, use x-ref responsibly.


Alpine.js is a powerful tool for adding interactivity without the overhead of larger frameworks. By understanding and utilizing its template syntax and directives, you can create dynamic, responsive, and maintainable web interfaces with ease.

FAQ

You can find answers for commonly asked questions about templates.

1. What is Alpine.js and how does it compare to other JavaScript frameworks?

Alpine.js is a lightweight JavaScript framework designed for adding interactive behavior to your web pages. It's much simpler and more minimal than frameworks like React or Vue, making it ideal for smaller projects or when you want to enhance HTML without a complex build process.

2. 2. How do I start using Alpine.js in my project?

You add a script tag to your HTML, and you're ready to go, making it more like jQuery in terms of ease of use.

3. Can Alpine.js handle complex functionality like forms and animations?

Yes, Alpine.js can manage complex functionalities like form interactions and animations. For example, x-model is great for binding form inputs to data, and x-transition allows you to apply CSS transitions easily.

4. How do I handle AJAX requests in Alpine.js templates?

You can perform AJAX requests in Alpine.js using the Fetch API within your x-data objects or event handlers. Define a method in x-data that makes the fetch call, then update your data properties based on the response to dynamically reflect changes in the UI.

5. Can I Integrate Alpine.js with Laravel for Building Dynamic Web Pages?

Yes, Alpine.js works well with Laravel. You can use Blade templates for server-side rendering and sprinkle Alpine.js directives into your HTML for client-side interactivity, allowing you to build dynamic features without a heavy frontend framework.

6. How Do I Implement Two-Way Data Binding in Alpine.js Templates?

Alpine.js supports two-way data binding using the x-model directive. Apply x-model to form inputs to automatically sync the input value with a data property in x-data, enabling reactive updates as users interact with the form.