Dec. 2, 2026

htmx: modern interfaces without a single-page application

8 min read

For years there seemed to be only one way to build an interactive web interface: a single-page application in React or something similar, backed by an API that returns JSON. It works, but it comes at a cost: two applications to develop and maintain, state duplicated between browser and server, and more dependencies to keep up to date.

For many projects there is a simpler alternative. It's called htmx, and we use it more and more often, including on this site.

What is htmx?

htmx is a small JavaScript library that adds certain attributes to HTML. Using hx-get or hx-post, an element sends a request to the server; using hx-trigger, it determines when to send the request; and using hx-target and hx-swap, it chooses which part of the page to replace with the response.

The difference lies in what the server returns: not JSON data to be parsed in the browser, but the actual HTML to be displayed. The logic, permissions, and templates all remain on the server, where they already are.

A concrete example: our blog

If you scroll through the We talk article list, more posts appear when you reach the bottom, without reloading the page. That's htmx at work: as soon as the last item in the list becomes visible, it asks the server for the next page and is replaced by the new articles.

On the Django side, the work is minimal: the view recognizes that the request comes from htmx and, instead of returning the entire page, returns only the template fragment containing the articles. The same code also handles the tag filter. No dedicated API, no components to synchronize.

Why We Like It

  • Less code: the interface and logic are both part of the same project, using a single template language.
  • No need to build an API just for the front end, and therefore no second point where permissions and validations need to be checked.
  • Pages that load instantly with the content already in place—a benefit for SEO as well.
  • You introduce it piece by piece into an existing project, without rewriting everything.
  • Fewer JavaScript dependencies to keep up to date over the years.

When We Still Choose React

htmx doesn't replace everything. A single-page application is still the right choice when:

  • the interface keeps a lot of state in the browser, as in graphic editors, configurators or complex drag and drop;
  • the application also has to work offline;
  • there is also a React Native mobile app that shares components and logic with it;
  • the same backend has to serve several different clients through a public API.

Often the two live side by side: htmx for most pages and a React component only where it is really needed.

How We Use It with Django

With the django-htmx package, every view knows whether the request comes from htmx and can respond with the entire page or just a fragment. Partial templates are reused in both cases, and forms are validated on the server as usual: if there are errors, the form fragment is returned with the error messages already in place.

In summary

For B2B portals, management systems, restricted-access areas, and most websites with dynamic content, htmx meets most needs with far less complexity. This means developing faster, spending less on maintenance, and having an application that’s easier to evolve. If you’re considering a web interface redesign, we can help you determine which approach is right for you.