Working with HTMX?

HTMX swaps or triggers not firing right? We clear the backlog.

Small teams pick HTMX because it feels sane again: forms post to endpoints, the server returns HTML, and the page updates. Then an hx-swap targets the wrong element, hx-boost swallows a redirect, and nobody is sure whether the bug is in the attribute or the response. We trace the request, the headers and the swap, and leave the interactions behaving the way the markup claims.

  • Since 2015Fixing technology
  • FreeEstimates
  • US teamReal engineers

htmx-console.log

still broken

What it is

HTMX at a glance

HTMX is a small JavaScript library that lets HTML elements issue AJAX requests, trigger WebSocket and SSE updates, and swap server-rendered fragments into the page using attributes rather than framework code. It was created by Carson Gross and traces back to intercooler.js; the current HTMX line reached 1.0 in 2020 and 2.0 in 2024.

The pitch is hypermedia-first: the server returns HTML, the browser renders it, and the library handles the small bit of glue that makes forms and links behave like a single page application without the single page application. It suits internal tools, admin panels, small-business sites and anyone who would rather ship a Django, Rails or Flask back end with a thin dash of interactivity than build a separate client.

Type
Hypermedia-first interactivity library
First released
2020 as htmx, intercooler lineage dating to 2013
License
BSD 2-Clause (Zero-Clause for 2.x)
Maintained by
Big Sky Software and open-source contributors
Typically used for
Admin panels, internal tools, Django and Rails apps, content sites that need partial updates

The honest version

HTMX pros and cons

No technology is all upside. This is where HTMX earns its place and where it tends to cause trouble.

Where HTMX is strong

  • Tiny footprintThe library is around 14kb minified and has no runtime framework to initialize. A page loads, the attributes attach handlers, and nothing else happens until a user interacts.
  • The server stays the source of truthYour Django view, Rails controller or Flask route returns a fragment and the browser shows it. There is no second data model in the client to keep in sync.
  • Attributes read like Englishhx-get, hx-post, hx-target and hx-swap are discoverable from the HTML itself. A new developer can read a template and understand what the interactions do.
  • Works with any back endAny framework that can return HTML can serve HTMX. Teams on PHP, Ruby, Python, Go, Elixir or plain Node can adopt it without changing languages.
  • Progressive enhancement by defaultLinks and forms degrade to normal navigation when JavaScript is disabled or still loading, so the application works even if the enhancement does not.
  • A grown-up event systemhx-trigger covers clicks, revealed-on-scroll, intervals, keyups, debounced input, custom events and SSE. Most interaction patterns are a one-line change in markup.

Where HTMX bites

  • Complex client state fights the modelShopping carts, drag-and-drop editors and multi-step wizards with branching state end up needing Alpine, HyperScript or vanilla JavaScript glued on, and the simplicity wins narrow quickly.
  • Out-of-band swaps are powerful and sharphx-swap-oob updates multiple parts of the page from one response, which is handy until two endpoints race and the page ends up in a state neither request intended.
  • Error handling needs conventionA 500 from the server returns an empty swap by default, so a broken endpoint silently blanks the page unless you add an htmx:responseError handler.
  • History and the back button take workhx-push-url writes URL changes without a full page load. Without matching GET endpoints for every pushed URL, refreshes and bookmarks break in ways that look like a server bug.
  • Testing patterns are not standardThere is no React Testing Library equivalent. Teams land on Playwright or server-side integration tests, which take longer to set up and longer to run.
  • Content Security Policies interact oddlyHyperScript and htmx:eval both rely on evaluating code, which strict CSP headers block. Keeping both available needs nonces or hashes the team has to maintain.

Sound familiar?

Common HTMX problems we fix

The HTMX problems that bring people to us, and what you have once each one is fixed.

htmx:targetError - The target 'closest .row' was not found

A swap targets an element that is not there

A refactor renamed a wrapper class, or the response replaced the element that was supposed to receive the next swap, and the request has nowhere to land.

Target stable across swaps

htmx:responseError - 500 Internal Server Error

The endpoint throws but the page looks fine

The server returned a 500, HTMX did not swap anything, and nobody saw a message. The user clicks again, same result, and reports the page is broken.

Errors surfaced to the user

HX-Redirect header ignored

Server redirects do not reach the browser

An HX-Redirect response was returned to a form that was not inside an hx-boost, so HTMX treated it as a normal swap and the redirect was never honored.

Redirects follow through to the URL

hx-trigger="revealed" firing on initial load

Infinite scroll loads everything at once

A revealed trigger attached to a tall element that is already visible at page load, which fires once per matching element and pulls in the next five pages immediately.

Infinite scroll fires one page at a time

hx-push-url left the back button pointing at a fragment

The back button goes to a dead URL

A pushed URL that exists only inside the single-page flow, with no GET handler on the server, so a refresh or a back click returns a fragment with no layout around it.

Every pushed URL has a real GET

htmx:oobErrorNoTarget - no target found for out-of-band swap

Out-of-band swaps miss their target

An oob fragment with an id that is not present on the current page, usually after a conditional block was collapsed or a tab was not open when the response landed.

Out-of-band targets exist before the swap

CSP violation: inline script blocked

Strict CSP blocks htmx:eval and HyperScript

A deployed Content Security Policy without unsafe-inline, which blocks the eval paths HTMX uses for custom scripts and the HyperScript extension entirely.

CSP configured with the right nonces

no owner, no docs

A freelancer handed over a half-working HTMX app

A template full of attributes, a server that returns fragments nobody has documented, and no notes on which URLs are HTMX endpoints and which are full pages.

Routes documented, ownership in your hands

What we do

HTMX help, from rescue to upkeep

Get in touch about one failing swap, or hand us the whole app and we take it from there.

Rescue
Swaps that miss, forms that post into the void, redirects that never redirect. We find the handler, the header or the attribute that is wrong and get the interactions behaving.
Interaction design
Deciding when hx-boost helps and when it hides a bug, where out-of-band swaps are appropriate, and how to keep the back button honest while URLs change.
Back-end integration
Django, Rails, Flask, Phoenix and Laravel endpoints returning the right fragments with the right HX headers, cached where it helps and uncached where it must be.
Progressive enhancement audit
Confirming the app still works when JavaScript is slow, missing or blocked, so a flaky connection does not lock a user out of a form they need to submit.
Freelancer handovers
Taking over an HTMX app from a contractor, writing down which endpoints return HTML and which return fragments, and bringing templates back under version control.
Managed Tech
A regular pass over the templates, server routes and error handlers, so a quiet HTMX bug does not sit broken for a month before someone notices.

How it works

From first message to fixed

  1. Look Free estimate

    Tell us what's going wrong. We look at it, then tell you plainly what's wrong and what it will cost.

  2. Fix

    We fix the cause, not the symptom. If something is down, getting it back up comes first.

  3. Harden

    Backups, monitoring, updates and access, so the same problem can't quietly come back.

  4. Hand back or stay on

    You get a plain-language write-up. Or we stay on for hosting, upkeep and new work.

Often found together

Running HTMX alongside something else?

We work on the whole stack, so the problem can be wherever it actually is.

Questions

HTMX questions

Something else? Call+1 737 727 7327

When does HTMX make sense over React or Vue?

When the server already renders HTML, the interactions are mostly form submissions and partial refreshes, and nobody on the team is excited about owning a client-side build pipeline. Internal tools, content sites, admin panels and small-business apps often fit the shape cleanly. Dashboards with heavy client state, offline work or complex drag interactions usually do not.

Why does our HTMX form submit without updating the page?

The common causes are a response that is not HTML, a target selector that no longer matches anything on the page, a 500 the server swallowed, or a swap strategy that replaces the form itself before the next interaction can attach. We inspect the network tab, the swap event and the response body, and fix the point where the pipeline breaks.

How do we handle errors cleanly in HTMX?

By catching htmx:responseError and htmx:sendError at the body level and showing something visible when a request fails, by returning useful HTML even on 4xx responses so the user sees a message rather than nothing, and by making sure validation errors come back as form fragments rather than empty swaps. We wire the three together so a dropped request is never silent.

Can HTMX work with a Content Security Policy?

Yes, with care. Strict CSP without unsafe-inline will block HyperScript and htmx:eval, so if you need those features you add a nonce or a hash. If you stay on the hx-* attributes and keep logic in the markup rather than inline scripts, HTMX itself does not require any CSP loosening at all.

Should we add hx-boost to every link?

Usually no. hx-boost intercepts clicks and turns full page loads into swaps, which is useful on long-lived pages and harmful on flows that rely on a fresh page context. We add it to the layout where the speed gain is worth it and leave it off links that need a full navigation to reset state.

How much does HTMX help cost?

We quote for free. Describe which swaps are breaking or which flow is stuck, and a price comes back ahead of any work.

Free estimate

HTMX app giving you trouble?

Tell us what you're running and what's going wrong. A person reads it and comes back with an estimate.

  • No charge to find out what it will take
  • If it's urgent, say so

Replies come from a person. By sending, you authorize us to email you back. No marketing.