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.

  1. Most asked How do you show loading indicators and prevent double submits?

    During a request htmx adds the htmx-request class to the requesting element; elements with the htmx-indicator class inside it (or named by hx-indicator) become visible. hx-disabled-elt disables…

  2. Most asked How would you implement active search with htmx?

    A search input with hx-get to the search endpoint, hx-trigger="input changed delay:300ms, search", hx-target on the results container (for example the tbody), hx-sync="this:replace", an indicator,…

  3. Most asked How do you organise server templates for an htmx app?

    Put each fragment htmx requests in its own partial template (or use template fragments to render a named block), include it from the full page, and pick partial vs page based on HX-Request. Keep…

  4. How do you add htmx to a page?

    Include one script tag, ideally with a pinned version and an integrity hash, or install the htmx.org npm package and import it. No build step or initialisation code is needed; htmx processes the…

  5. How do you send values from elements outside the requesting element?

    Use hx-include with a selector (or closest form, find, this) to add those inputs' values, hx-vals to add JSON values, and hx-params to filter what is sent.

  6. How do you implement infinite scroll with htmx?

    The last item of each page is a loader that requests the next page with hx-trigger="revealed" (or intersect once inside a scroll container), hx-target="this" and hx-swap="outerHTML". The response…

  7. How do you build click-to-edit with htmx?

    Render a view fragment with an Edit button (hx-get to the edit URL). The server returns an edit form that replaces the view (hx-target="this" or closest tr, hx-swap="outerHTML"). Save sends hx-put…

  8. How do you implement real-time updates with htmx?

    Polling with hx-trigger="every 5s" (status 286 stops it), Server-Sent Events with the SSE extension (sse-connect, sse-swap) for one-way pushes, or WebSockets with the ws extension (ws-connect,…

  9. How do you test an htmx application?

    Test server endpoints like any web handler: request each URL with and without the HX-Request header and assert on status codes, response headers (HX-Trigger, HX-Redirect, Vary) and the returned…

  10. How do you confirm destructive actions in htmx?

    hx-confirm="message" shows the browser's confirm dialog and only sends the request if the user agrees. For custom dialogs, handle the htmx:confirm event, call preventDefault(), show your dialog, and…

Was this page helpful?

Report a mistake