---
title: "Datastar vs. Alpine & HTMX – The Better Choice for Craft CMS"
date: 2025-11-24T12:57:00+01:00
author: webworker
canonical_url: "https://craft-kit.dev/blog/datastar-vs-alpine-htmx-why-datastar-is-the-better-fit-for-craft-cms"
section: Blog
---
When building dynamic Craft CMS frontends, Alpine.js and HTMX are familiar choices. It's a popular combo — and it works. But after using both stacks on real Craft projects, I switched to Datastar and haven't looked back.

Here's why.

**This site is the working example.** Its navigation dropdowns, mobile menu and search panel use Datastar, just like the [blog filters](https://craft-kit.dev/blog) and [Todo List](/hypermedia-todolist-craft-cms-datastar). There is no Alpine layer for everyday UI state. Try the demos, then [inspect the Twig templates on GitHub](https://github.com/handplant/craftcms-lazy-starter-kit).

**Want to put this into practice?** Follow the [Craft and Datastar guide to live search, filters and navigation](https://craft-kit.dev/blog/datastar-craft-cms-live-search-filters-navigation-twig), with short code examples from this starter kit.

## The Hypermedia Renaissance

For years, the frontend world moved in one direction: more JavaScript, more complexity, more frameworks. React, Vue, Angular — and with them, build pipelines, hydration strategies, client-side state management, and a growing gap between backend and frontend.

Then came a quiet counter-movement. HTMX, Hotwire, and others reminded developers that the web was built on hypermedia — and that server-rendered HTML, sent over the wire, is still a powerful and underrated approach.

Datastar takes this further. It's not just "less JavaScript" — it's a complete rethink of where state lives, how the DOM updates, and what the browser is actually good at. The server drives the UI. The browser renders it. No SPA overhead, no hydration tax, no JavaScript fatigue.

For Craft CMS developers, this is a natural fit. Craft has always been server-first, Twig-first, content-first. Datastar speaks the same language.

## Where Sprig and Alpine Need More Coordination

Sprig brings HTMX into Craft as a first-class plugin — and it works well for isolated, self-contained components. A search box here, a filtered list there. Simple, declarative, Twig-friendly.

Sprig uses HTMX to re-render Twig components and update selected parts of the page. That is a practical model. When a page also has shared filters, live counters and browser-side interactions, I have found that coordinating Sprig and Alpine can require more decisions:

- **State ownership** — decide which values belong in form fields, URL parameters, Alpine stores or the server.
- **DOM boundaries** — replacement can affect local state and JavaScript widgets. Targeted swaps, preservation and morphing extensions help, but need deliberate setup.
- **Component communication** — Sprig supports refreshing other components and triggering events; the refresh relationships still need to be designed.
- **Shareable URLs** — Sprig supports push and replace URL behavior. Filters must still be restored from those URLs, just as they must with Datastar.
- **Multiple updates** — out-of-band swaps are useful. For my projects, a shared signal model and morphing responses are often easier to coordinate.

These are architectural trade-offs, not things Sprig cannot do. My preference for Datastar comes from reducing the amount of coordination I need to maintain.

---

## A Unified Model Changes Everything

Datastar is not just another library — it's a unified model. One tool that handles both server communication and client-side reactivity, built around the same server-first philosophy that makes Craft great.

For many interactions, I can use one set of attributes instead of coordinating two libraries. Third-party widgets still need careful initialization and cleanup.

Signals hold reactive values in the browser and can be patched by the server. Craft remains responsible for authoritative data, validation and permissions. Craft renders Twig; Datastar patches the response into the page.

---

## Why Datastar Fits Craft CMS Better Than Sprig

### 1. Shared State Across the Entire Page

Sprig has explicit component boundaries, with form values, URL parameters and refresh events connecting them. That can be a useful separation. I prefer a shared signal store when several parts of the page need the same reactive values.

Datastar provides a page-wide signal store. A filter value can be read by a results list, a counter and a reset button without a separate state bridge. I namespace signals so reusable components do not accidentally share state.

### 2. DOM Morphing That Doesn't Break Your UI

A replacement swap can discard local state inside its target. Sprig also offers targeted replacement and preservation, and its documentation describes using a morphing extension. It is not limited to replacing every component in full.

Datastar uses DOM morphing for element patches by default. It reconciles the returned HTML with the existing nodes, which helps preserve browser state. Stable IDs and clear ownership boundaries still matter, especially around maps, sliders and other JavaScript integrations.

### 3. Polling Done Right

Both Sprig and Datastar can poll an endpoint. In Datastar, **data-on-interval** can run an expression that sends a request; the server still performs its queries and renders the response. Morphing can reduce DOM disruption, but does not automatically reduce server work or response size.

Datastar also supports streamed updates over Server-Sent Events. Long-lived streams are possible with PHP, but require suitable worker capacity, timeouts and buffering settings. A short request-response interaction is often enough for a Craft website; persistent connections are an architectural choice, not a requirement.

### 4. A Natural Next Step From Sprig

If you know Sprig, parts of Datastar will feel familiar: server-rendered HTML, Twig templates and no separate frontend application. Signals and streamed responses introduce their own concepts, so I would migrate a real feature first rather than rewrite a working project wholesale.

The payoff, for me, is a more consistent model across server requests and browser-side reactivity.

### 5. One Tool Instead of Two

Sprig handles server communication. Alpine handles client reactivity. You handle everything in between.

Datastar does both — natively, consistently, without glue code.

---

## What Makes Datastar Fundamentally Different

These aren't just feature differences — they're philosophical ones.

### The Server Is the Source of Truth

I keep business rules, saved content and permissions on the server. Datastar signals handle transient browser state, such as an open panel or an unsent search term. They are untrusted input, not a substitute for server-side validation. Sprig and Alpine can follow the same principle; Datastar gives me a convenient way to implement it.

### Progressive Enhancement by Design

Datastar can enhance standard links and forms, but a useful no-JavaScript path is not automatic. I provide real URLs, form actions and server-rendered results first, then enhance the interaction. The same care is needed with Sprig. A button whose only behavior is a Datastar expression will not work without JavaScript.

### Fat Morph — Send the Whole Page, Patch What Changed

Datastar can reconcile a larger HTML region rather than requiring every change to have its own tiny response target. That can simplify template composition. The full returned HTML still travels over the network, so response size, query performance and stable element IDs still deserve attention.

### A CQRS-Style Pattern When You Need It

You can separate a long-lived GET stream for updates from short-lived POST requests for mutations. This is a useful pattern for live interfaces, but collaboration still needs backend event delivery, authorization and a hosting setup that supports the streams. Datastar supplies the browser-side primitives, not that entire application architecture.

### Server-Confirmed Mutations

For content changes, I prefer to show a loading state, wait for validation and update the UI from the server response. Datastar supports this straightforwardly. It is a design choice, not a guarantee provided by the library; errors and retries still need useful feedback.

---

## When Sprig Is Still a Good Choice

Simple, isolated interactions — a toggle, a basic component reload, a single filtered list — Sprig handles perfectly. If your project never needs shared state or real-time updates, Sprig is a solid choice.

A working Sprig implementation does not need replacing just because another tool exists. Team experience, existing components and project requirements matter. I choose Datastar when its shared signals and response model make the next feature simpler.

---

## Useful Datastar Attributes in One Place

Several everyday behaviors are available through one consistent attribute system. Some have equivalents in HTMX or Alpine; the advantage for me is using them together without another integration layer.

**data-on-intersect** fires when an element enters the viewport — perfect for lazy-loaded content or scroll-triggered requests, no JavaScript needed. **data-indicator** automatically tracks request state for loading spinners and disabled buttons, purely in HTML. **data-computed** creates reactive derived values that stay in sync automatically. And debounce/throttle are built directly into the event system as modifiers — **data-on:input\_\_debounce.300ms** adds a delay before an input handler runs; a live search also needs a signal binding, a request action and an endpoint.

For URL sync specifically: **data-query-string** (Pro) keeps signal values in sync with URL parameters including browser history — a convenient option rather than a capability exclusive to Datastar. Sprig also supports pushing and replacing URLs.

Small things. But they add up. 👉 [See the full list of Datastar attributes](https://data-star.dev/reference/attributes)

---

## Conclusion

Sprig and Alpine are good tools. But for modern Craft CMS projects, Datastar fits the architecture better — server-first, Twig-native, with shared signals and streaming support when the project needs it.

Less glue code. Fewer bugs. More fun to build with.

---

## Datastar in Craft CMS — Made Easy by Ben Croker

Getting started with Datastar in Craft is straightforward — thanks to the [**Craft Datastar Plugin**](https://putyourlightson.com/plugins/datastar) by Ben Croker of PutYourLightsOn.

The plugin handles the Craft-specific integration out of the box: SSE responses from Twig templates, action routing, and all the wiring that would otherwise require custom boilerplate. It's the missing piece that makes Datastar a first-class citizen in Craft — just like Sprig did for HTMX.

A big thank you to Ben Croker for building and maintaining this. Without it, the barrier to getting started with Datastar in Craft would be significantly higher.

👉 [putyourlightson.com/plugins/datastar](https://putyourlightson.com/plugins/datastar)

---

If you want to see Datastar in action inside real Craft CMS projects, take a look at the live demos at craft-kit.dev:

- [**Dynamic Blog**](https://craft-kit.dev/blog) — filtering and pagination without a page reload
- [**Todo List**](/hypermedia-todolist-craft-cms-datastar) — add, complete and delete tasks with server-confirmed updates
- [**Map Filtering**](https://craft-kit.dev/map) — location-based filtering with live updates
- [**Live Search**](https://craft-kit.dev/search) — instant search results, server-driven

These examples show how the starter kit puts the approach into practice. Try a demo, then inspect its Twig templates and Datastar endpoints on GitHub. The [Builder demo](https://craft-kit.dev/builder#matrix) also shows how Matrix and CKEditor share the same component templates.

The full source code is available on GitHub — feel free to explore, fork, and use it as a starting point:  
👉 <https://github.com/handplant/craftcms-lazy-starter-kit>

For a deeper dive into the philosophy behind Datastar, read The Tao of Datastar:  
👉 <https://data-star.dev/guide/the_tao_of_datastar>

For Craft-specific integration details, use the [Datastar plugin documentation](https://putyourlightson.com/plugins/datastar). For independent Craft examples, see [Datastar & Craft CMS Demos](https://craftcms.data-star.dev/). For the comparison above, the [Sprig documentation](https://putyourlightson.com/plugins/sprig) also covers preservation, URL updates and component refreshes.

---

**Building a Craft CMS project and want to go the Datastar route?** I'm Andi Grether, a freelance Craft CMS developer specializing in exactly this stack. Happy to help — [webworker.me](https://webworker.me)
