Date: 2024.01.29 | alpine | create | featured | htmx | tech |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
Low-js tools like HTMX and AlpineJS are the future of the web. They allow us to build modern web apps without the bloat of popular SPA frameworks.
I've been researching and experimenting with low-js technologies for the past year, eventually deciding to build my apps with HTMX + F# instead of SvelteKit. I've found the low-js approach to be much simpler while providing all the power I need to build modern web apps.
One of the things that took me awhile to understand (and that I see a good amount of confusion about in the community) is how to choose between low-js tools HTMX and Alpine for your apps. Some guides will use one or the other, others both.
So in this post I want to clarify the differences so you can make the best choice for your web app.
The decision between HTMX and AlpineJS is not an exclusive one. These are not competing tools offering the same functionality (though there is overlap in what each of them can do). Instead, we should view them as complimentary tools.
They work well together because they focus on solving common but different aspects of web app development.
Plus both are fundamental low-js tools meaning they provide these functionalities without unnecessary baggage:
So these work well together which is why you'll see just as many apps using both as you might using just one or using one with a different lib.
Now that we've seen the similarities, let's talk about what each is uniquely good at.

Image from Simple Interactive Islands with F# and HTMX
HTMX is focused on making server interactivity simple and powerful. Its unique trait is that it's hyper-focused on Hypermedia controls.
What this means for us is that it controls everything via HTML attributes.
This may not seem like much but the ability to do partial page reloads is actually the fundamental thing that SPAs do to feel fast. So HTMX allows you to build the same modern-feeling apps, just simpler, faster, and cheaper.
So when should you use HTMX?
HTMX is great for building web apps that require server interactivity - displaying and updating data located on the server. For these cases, reach for HTMX.
While most interactivity (~80%+) you might want in a web app works well with HTMX's SSR HTML approach, it may not be the best tool for everything.
For example, there are some things we might want to build to make the user experience better that doesn't rely on or impact any data the server has. Things like showing or hiding a modal or interacting with a JS library on your web page that only live on the client don't really gain anything from asking the server for information. In fact trying to ask the server for information on things that only live on the client can be quite awkward and slow (network requests are not the fastest thing in the world).
This is where AlpineJS shines and why Alpine (or another lightweight client interactivity library) is often used alongside HTMX.
AlpineJS takes a similar low-js approach allowing you to declare clientside state and functionality in a simple, concise way directly in your HTML. This allows it to play very nice with HTMX as all your minimal logic declarations can be declared and viewed all in one place (Locality of Behavior).
So when should you use AlpineJS?
AlpineJS is great for sprinkling client interactivity in your app with minimal JS overhead. When it doesn't make sense to ask the server for something, AlpineJS can fill in the gaps.
So far I've really been enjoying building web apps with HTMX + Alpine. I've found it allows me to build my web apps faster and cheaper than the SPAs ever did.
Plus it doesn't lock me into a specific technology (like Node) so I can build fullstack apps with F# (my fave language) and HTMX + Alpine for frontend interactivity. This is the power of the HOWL stack (Hypermedia on Whatever you Like).
If you liked this post you might also like:
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.