htmx is a small JavaScript library that lets you build interactive web pages using only HTML attributes. Click a button, and part of the page updates β no JavaScript framework, no build step, no state management. If you like HTML and you are tired of reaching for a heavy framework for simple interactions, htmx is worth learning.
The idea is that HTML was always meant to be interactive, but the browser only gave you two tools: links and forms, both of which reload the whole page. htmx extends HTML so any element can make a request and swap part of the page with the response. A button that loads more items looks like this:
<script src = "https://unpkg.com/[email protected]" ></script>
<button hx-get = "/more-items" hx-target = "#results" hx-swap = "beforeend" > Load more </button>
<div id = "results" ></div>
Enter fullscreen mode
Exit fullscreen mode
Click the button, and htmx fetches /more-items from your server and appends the response to #results .β¦