English for HTMX
Learn the English vocabulary for discussing HTMX, including hypermedia-driven applications, HTML attributes for AJAX, and swapping strategies.
HTMX pitches itself against the entire modern frontend framework stack, so discussing it well means understanding the philosophy behind the attributes, not just what each one does mechanically.
Key Vocabulary
Hypermedia-driven application — HTMX’s core philosophy: the server returns HTML fragments in response to user actions, and the browser swaps them into the page, rather than the client managing state and rendering via JavaScript. “This is a hypermedia-driven application, not a single-page app — when the user clicks that button, the server renders the updated HTML and sends it back, the client isn’t holding application state in JavaScript at all.”
hx-get / hx-post — HTMX attributes that trigger an AJAX request to a URL when an element is interacted with, replacing the need to write fetch calls or event handlers in JavaScript for common interactions. “We don’t need a click handler and a fetch call for this — hx-post on the button sends the request directly, and the response HTML gets swapped into the page automatically.”
hx-swap — the attribute controlling how the response HTML is inserted relative to the target element, with values like innerHTML, outerHTML, beforeend, or afterbegin determining the exact insertion behavior.
“The new item wasn’t appearing where we expected because hx-swap was set to innerHTML, replacing the container’s contents, when we actually wanted beforeend to append the new item to the existing list.”
hx-target — the attribute specifying which element on the page should receive the swapped HTML, when it isn’t the element that triggered the request, letting one interaction update a different part of the page. “The form submission needs to update the results panel, not itself, so we set hx-target to point at that panel’s id rather than letting the response replace the form.”
Server-rendered fragment — the piece of HTML the server returns in response to an HTMX request, typically just the changed portion of the page rather than a full page reload, keeping payloads small and logic on the server. “The endpoint doesn’t return a full page or JSON — it returns a server-rendered fragment, just the updated table row, which HTMX swaps directly into place.”
Common Phrases
- “Is this a hypermedia-driven interaction, or do we actually need client-side state here?”
- “Should this be hx-get or hx-post, based on whether it’s idempotent?”
- “What hx-swap strategy do we want — replace, append, or something else?”
- “Does this need an explicit hx-target, or is it updating the triggering element itself?”
- “Is the server returning a full page here, or just the fragment we need?”
Example Sentences
Explaining the architectural tradeoff: “We chose a hypermedia-driven application here deliberately — this admin tool doesn’t need complex client-side state, so we avoided a JavaScript framework entirely and let the server just return HTML fragments for each interaction.”
Debugging a swap issue: “The list wasn’t updating correctly because hx-swap was set to outerHTML, which replaces the entire target element including the id HTMX needs to find it again next time — switching to innerHTML fixed it.”
Justifying a targeting decision: “This search box needs hx-target pointing at the results div, not itself, since the input that triggers the request isn’t the element that should receive the new HTML.”
Professional Tips
- Frame HTMX as building a hypermedia-driven application when explaining the approach to a team used to SPAs — it’s a genuinely different architecture, not a lighter version of React.
- Choose hx-get for idempotent, safe requests and hx-post for anything that changes state, following the same semantics as the underlying HTTP methods.
- Be deliberate about hx-swap strategy — the default of replacing inner HTML is often wrong for lists or logs where you actually want to append or prepend.
- Use hx-target whenever the element triggering the request isn’t the one that should be updated — omitting it is a common source of “nothing happened” bugs.
- Keep the server-rendered fragment minimal and focused on exactly what changed — returning more than necessary undercuts the bandwidth and simplicity benefits of the approach.
Practice Exercise
- Explain what “hypermedia-driven” means and how it differs from a typical single-page app.
- Describe a situation where you’d need hx-target instead of letting the response replace the triggering element.
- Write a sentence explaining the difference between hx-swap values innerHTML and beforeend.