Essay - Published: 2024.07.31 | create | htmx | tech |
DISCLOSURE: If you buy through affiliate links, I may earn a small commission. (disclosures)
I recently built a side project that heavily relies on HTMX polling. In this post we'll dive into how it works, examples of how to implement polling with HTMX, and ideas for how you might use this in your own projects.
I like building side projects with HTMX so naturally I built my latest side project (1000 checkboxes) with it. We'll start with an overview of how it works to give context for how HTMX polling is used.
How 1000 checkboxes works:
Under the hood it uses HTMX polling to get the latest checkbox state every few seconds (and minimize the amount of HTML we send on each poll).
Learn more:
Now that we know how the project works we can dive into how it uses HTMX for polling.

The page is served as an MPA with the checkbox grid being an Interactive Island. An Interactive Island is essentially a ~self-contained component that can re-render itself when it needs to. I like the Interactive Island paradigm for HTMX componentization because I find it allows you to leverage the power of HTMX while minimizing extra complexity.
To setup polling with HTMX we are going to use the hx-trigger attribute to configure when our component decides to refresh itself. Here we set it to trigger on load with a delay effectively creating a polling scenario where it refreshes itself on each delay.
This component:
CheckboxGridhx-target="#CheckboxGrid"hx-get="/"hx-trigger="load delay:5s"The backend:
CheckboxGridHTML code:
<div id="CheckboxGrid" hx-get="/" hx-target="#CheckboxGrid" hx-trigger="load delay:5s" class="grid place-items-center">
<input type="checkbox" name="0" checked="" hx-post="/update-checkbox/0" hx-trigger="change" hx-swap="none" class="checkbox checkbox-md">
<input type="checkbox" name="0" checked="" hx-post="/update-checkbox/1" hx-trigger="change" hx-swap="none" class="checkbox checkbox-md">
<!-- More checkboxes here -->
</div>
You can see this code in action at https://1000checkboxes.xyz/
Okay so we've gone over a simple example of web polling with HTMX but I wanted to provide some ideas for how you might use this in your own projects.
I've now been playing with HTMX for ~6 months and have been very happy with it for building my side projects. It feels like a Simple Scalable System for building simple webapps as MPAs and sprinkling in some dynamism when useful. Hopefully this post helps you along with your next HTMX project.
Q: How are you using HTMX in your projects? What's been the hardest thing to do with it?
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.