โก HTMX Dictionary
Every keyword, operator, and symbol โ with plain-English explanations.
HX-Redirect headerResponse header: instructs the browser to navigate to a new URL.
w.Header().Set("HX-Redirect", "/login")HX-Refresh headerResponse header: tells HTMX to do a full page refresh.
w.Header().Set("HX-Refresh", "true")afterbegin swapInserts the response HTML at the start of the target's children.
hx-swap="afterbegin"
afterend swapInserts the response HTML after the target element.
hx-swap="afterend"
beforebegin swapInserts the response HTML before the target element.
hx-swap="beforebegin"
beforeend swapInserts the response HTML at the end of the target's children.
hx-swap="beforeend"
htmx-indicator classAdd this class to elements you want shown only during a request (via hx-indicator).
<span class="htmx-indicator">Loading...</span>
hx-delete attributeMakes a DELETE request to the given URL when triggered.
<button hx-delete="/item/1">Delete</button>
hx-disable attributeDisables HTMX processing on the element and its children.
<div hx-disable>...</div>
hx-ext attributeEnables HTMX extensions on the element.
<div hx-ext="json-enc">...</div>
hx-headers attributeAdds custom HTTP headers to the request.
<div hx-get="/secure" hx-headers='{"X-Token":"abc"}'>hx-indicator attributePoints to an element to show while the request is in flight.
<button hx-get="/slow" hx-indicator="#spin">Load</button>
hx-on attributeAttaches an inline event handler to HTMX lifecycle events.
<div hx-on:htmx:afterSwap="doSomething()">
hx-patch attributeMakes a PATCH request to the given URL when triggered.
<button hx-patch="/item/1">Patch</button>
hx-push-url attributePushes the request URL into the browser history after a successful response.
<a hx-get="/page" hx-push-url="true">Page</a>
hx-put attributeMakes a PUT request to the given URL when triggered.
<button hx-put="/item/1">Update</button>
hx-select attributeSelects a subset of the server response HTML to swap in.
<div hx-get="/page" hx-select="#content">...</div>
hx-sync attributeControls how concurrent requests from the same element are handled.
<input hx-get="/search" hx-sync="closest form:abort">
hx-vals attributeAdds extra values to the request as JSON.
<button hx-post="/do" hx-vals='{"key":"val"}'>Go</button>innerHTML swapDefault swap: replaces the inner HTML of the target element.
hx-swap="innerHTML"
none swapNo DOM swap โ useful when you only want a server side-effect.
hx-swap="none"
outerHTML swapReplaces the entire target element including its tag.
hx-swap="outerHTML"
hx-get attributeHTTP GET request to URL when triggered.
<button hx-get="/data">Load</button>
hx-post attributeHTTP POST request to URL when triggered.
<form hx-post="/submit">
hx-trigger attributeWhat event triggers the request.
hx-trigger="keyup changed delay:300ms"
hx-target attributeCSS selector of element where response goes.
hx-target="#result"
hx-swap attributeHow response HTML is inserted.
hx-swap="outerHTML"
hx-trigger:click TRIGGERTriggers on a click event.
hx-trigger="click" on a button
click TRIGGERTriggers an event when the element is clicked.
<button hx-trigger="click" hx-swap="outerHTML" hx-get="/api/data">Click Me</button>
hx-confirm attributeShows confirm dialog before request.
hx-confirm="Are you sure?"
hx-trigger:submit TRIGGERTriggers on a form submission.
hx-trigger="submit" on a form
hx-boost attributeUpgrades links/forms to use HTMX.
<div hx-boost="true">
hx-trigger:change TRIGGERTriggers on a change event.
hx-trigger="change" on an input
submit TRIGGERTriggers an event when the form is submitted.
<form hx-trigger="submit" hx-swap="outerHTML" hx-post="/api/data">...</form>
change TRIGGERTriggers an event when the value of the element changes.
<input type="text" hx-trigger="change" hx-swap="outerHTML" hx-get="/api/data">
hx-include attributeIncludes other element values in request.
hx-include="#extra"
hx-trigger:keyup TRIGGERTriggers on a keyup event.
hx-trigger="keyup" on an input
HX-Request headerRequest header sent by HTMX.
r.Header.Get("HX-Request")hx-trigger:keydown TRIGGERTriggers on a keydown event.
hx-trigger="keydown" on an input
keyup TRIGGERTriggers an event when a key is released after being pressed.
<input type="text" hx-trigger="keyup" hx-swap="outerHTML" hx-get="/api/data">
HX-Trigger headerResponse header to trigger client events.
w.Header().Set("HX-Trigger","ev")hx-trigger:focus TRIGGERTriggers on a focus event.
hx-trigger="focus" on an input
keydown TRIGGERTriggers an event when a key is pressed.
<input type="text" hx-trigger="keydown" hx-swap="outerHTML" hx-get="/api/data">
focus TRIGGERTriggers an event when the element gains focus.
<input type="text" hx-trigger="focus" hx-swap="outerHTML" hx-get="/api/data">
hx-trigger:blur TRIGGERTriggers on a blur event.
hx-trigger="blur" on an input
blur TRIGGERTriggers an event when the element loses focus.
<input type="text" hx-trigger="blur" hx-swap="outerHTML" hx-get="/api/data">
hx-trigger:load TRIGGERTriggers on a load event.
hx-trigger="load" on a div
hx-trigger:revealed TRIGGERTriggers on an intersection event.
hx-trigger="revealed" on a div
load TRIGGERTriggers an event when the document or an element is fully loaded.
<div hx-trigger="load" hx-swap="outerHTML" hx-get="/api/data">Loading...</div>
hx-trigger:intersect every:1000s TRIGGERTriggers on an intersection event every 1000 seconds.
hx-trigger="intersect every:1000s" on a div
revealed TRIGGERTriggers an event when an element is revealed (e.g., shown in the viewport).
<div hx-trigger="revealed" hx-swap="outerHTML" hx-get="/api/data">Revealed</div>
hx-trigger:from:selector TRIGGERTriggers on an element that matches the selector.
hx-trigger="from:input[type='text']" on a div
intersect TRIGGERTriggers an event when an element intersects the viewport.
<div hx-trigger="intersect" hx-swap="outerHTML" hx-get="/api/data">Intersect</div>
every:Ns TRIGGERTriggers an event every N milliseconds.
<div hx-trigger="every:1000" hx-swap="outerHTML" hx-get="/api/data">Every 1s</div>
hx-trigger:target:selector TRIGGERTriggers on a target element that matches the selector.
hx-trigger="target:input[type='text']" on a div
from:selector TRIGGERTriggers an event based on a selector.
<div hx-trigger="from:#myform" hx-swap="outerHTML" hx-get="/api/data">From Selector</div>
hx-trigger:consume queue:first TRIGGERTriggers on the first element in the queue.
hx-trigger="consume queue:first" on a div
hx-trigger:consume queue:last TRIGGERTriggers on the last element in the queue.
hx-trigger="consume queue:last" on a div
target:selector TRIGGERTargets the event to a specific selector.
<div hx-trigger="target:#result" hx-swap="outerHTML" hx-get="/api/data">Target Selector</div>
consume TRIGGERDetermines how the event is handled (queue/none).
<button hx-trigger="click" hx-consume="queue" hx-swap="outerHTML" hx-get="/api/data">Consume Queue</button>
hx-trigger:consume queue:all TRIGGERTriggers on all elements in the queue.
hx-trigger="consume queue:all" on a div
hx-trigger:consume queue:none TRIGGERTriggers on no elements in the queue.
hx-trigger="consume queue:none" on a div
queue:first TRIGGERQueues the request and processes the first in the queue first.
<button hx-trigger="click" hx-consume="queue:first" hx-swap="outerHTML" hx-get="/api/data">Queue First</button>
hx-trigger:delay:1000ms TRIGGERTriggers after a delay of 1000 milliseconds.
hx-trigger="delay:1000ms" on a button
queue:last TRIGGERQueues the request and processes the last in the queue first.
<button hx-trigger="click" hx-consume="queue:last" hx-swap="outerHTML" hx-get="/api/data">Queue Last</button>
hx-trigger:throttle:1000ms TRIGGERTriggers with throttle of 1000 milliseconds.
hx-trigger="throttle:1000ms" on a button
queue:none TRIGGERDoes not queue the request, processes immediately.
<button hx-trigger="click" hx-consume="queue:none" hx-swap="outerHTML" hx-get="/api/data">Queue None</button>
delay:ms TRIGGERDelays the execution of the event handler by the specified number of milliseconds.
<button hx-trigger="click" hx-delay="2000" hx-swap="outerHTML" hx-get="/api/data">Delay 2s</button>
hx-trigger:once TRIGGERTriggers only once.
hx-trigger="once" on a button
hx-trigger:filter[cond] TRIGGERTriggers with a filter condition.
hx-trigger="filter[cond] on a button
throttle:ms TRIGGERDebounces the event handler execution to avoid excessive calls within the specified time.
<input type="text" hx-trigger="keyup" hx-throttle="500" hx-swap="outerHTML" hx-get="/api/data">
hx-target:css-selector TARGETSets the target element using a CSS selector.
hx-target="#my-target" on a div
once TRIGGERExecutes the event handler only once, even if the trigger is fired multiple times within the specified time.
<input type="text" hx-trigger="keyup" hx-once="2000" hx-swap="outerHTML" hx-get="/api/data">
filter[cond] TRIGGERFilters the event based on a condition.
<button hx-trigger="click" hx-filter="data:ok" hx-swap="outerHTML" hx-get="/api/data">Filter Condition</button>
hx-target:closest:sel TARGETSets the target element to the closest match of the selector.
hx-target="closest:input[type='text']" on a div
hx-target:find:sel TARGETSets the target element to the first match of the selector within the current element.
hx-target="find:input[type='text']" on a div
closest:sel TARGETTargets the closest ancestor element matching the selector.
<div hx-target="closest:#mydiv" hx-swap="outerHTML" hx-get="/api/data">Closest Selector</div>
hx-target:next:sel TARGETSets the target element to the next sibling matching the selector.
hx-target="next:input[type='text']" on a div
find:sel TARGETFinds the first element matching the selector within the target element.
<div hx-target="find:#mydiv" hx-swap="outerHTML" hx-get="/api/data">Find Selector</div>
hx-target:previous:sel TARGETSets the target element to the previous sibling matching the selector.
hx-target="previous:input[type='text']" on a div
hx-target:this TARGETSets the target element to the current element.
hx-target="this" on a div
next:sel TARGETTargets the next sibling element matching the selector.
<div hx-target="next:#mydiv" hx-swap="outerHTML" hx-get="/api/data">Next Selector</div>
hx-swap:innerHTML SWAPReplaces the innerHTML of the target element.
hx-swap="innerHTML" on a div
previous:sel TARGETTargets the previous sibling element matching the selector.
<div hx-target="previous:#mydiv" hx-swap="outerHTML" hx-get="/api/data">Previous Selector</div>
hx-swap:outerHTML SWAPReplaces the outerHTML of the target element.
hx-swap="outerHTML" on a div
this TARGETTargets the current element.
<button hx-get="/api/data" hx-swap="outerHTML" hx-target="this">Get Data</button>
hx-swap:beforebegin SWAPInserts content before the target element.
hx-swap="beforebegin" on a div
hx-swap:afterbegin SWAPInserts content after the target element.
hx-swap="afterbegin" on a div
hx-swap:beforeend SWAPInserts content before the target element's end.
hx-swap="beforeend" on a div
hx-swap:afterend SWAPInserts content after the target element's end.
hx-swap="afterend" on a div
hx-swap:delete SWAPRemoves the target element and its content.
hx-swap="delete" on a div
hx-swap:none SWAPDoes nothing, no swap occurs.
hx-swap="none" on a div
hx-swap:swap:1000ms SWAPReplaces the target element with a delay of 1000 milliseconds.
hx-swap="swap:1000ms" on a div
queue SWAPQueues the swap action and processes the first in the queue first.
<div hx-get="/api/data" hx-swap="queue">Swap Queue</div>
hx-swap:settle:1000ms SWAPSettles the swap after a delay of 1000 milliseconds.
hx-swap="settle:1000ms" on a div
hx-swap:transition:true SWAPApplies a CSS transition to the swap.
hx-swap="transition:true" on a div
remove SWAPRemoves the target element and its contents.
<div hx-get="/api/data" hx-swap="remove">Swap Remove</div>
hx-swap:scroll:top SWAPScrolls the target element to the top after the swap.
hx-swap="scroll:top" on a div
text SWAPReplaces the text content of the target element with the response.
<div hx-get="/api/data" hx-swap="text">Swap Text</div>
hx-swap:scroll:bottom SWAPScrolls the target element to the bottom after the swap.
hx-swap="scroll:bottom" on a div
insertbefore SWAPInserts the response before the target element.
<div hx-get="/api/data" hx-swap="insertbefore">Swap InsertBefore</div>
hx-swap:focus-scroll:false SWAPDoes not focus the target element after the swap.
hx-swap="focus-scroll:false" on a div
insertafter SWAPInserts the response after the target element.
<div hx-get="/api/data" hx-swap="insertafter">Swap InsertAfter</div>
empty SWAPRemoves all child nodes of the target element.
<div hx-get="/api/data" hx-swap="empty">Swap Empty</div>
hx-include:name REQUEST CONTROLIncludes a variable in the request body.
hx-include="name" on a form
append SWAPAppends the response to the target element.
<div hx-get="/api/data" hx-swap="append">Swap Append</div>
hx-params:name REQUEST CONTROLAdds a parameter to the request URL.
hx-params="name=John" on a form
hx-params:[] REQUEST CONTROLAdds an array of parameters to the request URL.
hx-params="[1,2,3]" on a form
prepend SWAPPrepends the response to the target element.
<div hx-get="/api/data" hx-swap="prepend">Swap Prepend</div>
hx-params:[]:1 REQUEST CONTROLAdds an indexed parameter to the request URL.
hx-params="[1,2,3]:1" on a form
hx-params:[]:1:1 REQUEST CONTROLAdds a nested indexed parameter to the request URL.
hx-params="[1,2,3]:1:1" on a form
attr SWAPUpdates an attribute of the target element with the response.
<div hx-get="/api/data" hx-swap="attr:data-foo">Swap Attr</div>
hx-params:name[] REQUEST CONTROLAdds an array of parameters to the request URL.
hx-params="name[]=John&name[]=Doe" on a form
class SWAPUpdates the class attribute of the target element with the response.
<div hx-get="/api/data" hx-swap="class">Swap Class</div>
hx-params:name[]:1 REQUEST CONTROLAdds an indexed parameter to the request URL.
hx-params="name[1]=Doe" on a form
hx-params:name[]:1:1 REQUEST CONTROLAdds a nested indexed parameter to the request URL.
hx-params="name[1][1]=Doe" on a form
style SWAPUpdates the style attribute of the target element with the response.
<div hx-get="/api/data" hx-swap="style">Swap Style</div>
html SWAPReplaces the HTML content of the target element with the response.
<div hx-get="/api/data" hx-swap="html">Swap HTML</div>
hx-params:name[]:1:1:1 REQUEST CONTROLAdds a deeply nested indexed parameter to the request URL.
hx-params="name[1][1][1]=Doe" on a form
hx-params:name[]:1:1:1:1 REQUEST CONTROLAdds a deeply nested indexed parameter to the request URL.
hx-params="name[1][1][1][1]=Doe" on a form