Interview Q&A · questions with model answers
htmx Interview Questions
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked How does hx-trigger work? Give examples of modifiers and special triggers.
hx-trigger names the event that sends the request (defaults: change for inputs, submit for forms, click otherwise). Modifiers: once, changed, delay:<t> (debounce), throttle:<t>, from:<selector>,…
-
Most asked How do you handle form validation errors with htmx?
Keep browser validation (required, type=email) for instant feedback, and always validate on the server. On errors, return the form with the user's values and messages, ideally with status 422. htmx…
-
Most asked Explain the htmx request lifecycle.
An event triggers an element; htmx collects values and headers and sends the request; the server returns HTML; htmx swaps it into the target using the swap style; then it settles, processing htmx…
-
Most asked What happens in htmx 2 when the server returns 204, 404 or 500?
None of them are swapped by default. 204 means 'nothing to swap'. 4xx and 5xx fire htmx:responseError and leave the page unchanged; a network failure fires htmx:sendError and a timeout fires…
-
Most asked How can the server trigger client-side events, and why is that useful?
With the HX-Trigger response header: a single event name, a comma-separated list, or JSON with details ({"showMessage": "Saved"}). The event fires on the triggering element and bubbles, so other…
-
Most asked How do you make third-party widgets work in content loaded by htmx?
Initialise them in htmx.onLoad(callback) (the htmx:load event), which runs for the initial page and every piece of new content htmx adds. If your own JavaScript inserts HTML containing hx-…
-
Most asked A user reloads a page whose URL was pushed by htmx and sees an unstyled fragment. What's wrong?
The endpoint returns the same fragment to every request. On reload the browser requests the URL directly, without HX-Request, and needs the full page. Check HX-Request (and…
-
Most asked How do you handle CSRF tokens with htmx?
Send the token as a header on every request: hx-headers='{"X-CSRFToken": "..."}' on <body> is inherited by all htmx requests, or add it in an htmx:configRequest listener. Use the header name your…
-
How does attribute inheritance work in htmx 2, and what changes in htmx 4?
In htmx 2 most attributes (hx-target, hx-swap, hx-confirm, hx-headers, hx-boost...) are inherited implicitly by descendants, and hx-disinherit/hx-inherit adjust that. In htmx 4 inheritance is…
-
Where did htmx come from?
htmx is the successor of intercooler.js, a jQuery-based library Carson Gross created in 2013. He rewrote it without jQuery as htmx in 2020; htmx 1.0 was released in November 2020, htmx 2.0 in June…