Swapping
Swapping with HTMX involves dynamically replacing a portion of your webpage’s content with new data from the server without a full page reload, utilizing custom hx-swap attributes to define how the content should be transitioned. Out‑of‑band swapping extends this concept by allowing parts of the webpage outside the target element to be updated simultaneously, specified by the hx-swap-oob attribute, which is useful for updating multiple sections of a page in response to a single HTMX request. This mechanism facilitates more interactive and responsive web applications by minimizing the need for full page refreshes and enabling precise control over which parts of the page are updated.
HTMX 4 Update
In HTMX 4 the main swap is performed first and any out‑of‑band (hx-swap-oob) or <hx-partial> swaps occur afterwards. Consider structuring your response accordingly if you rely on OOB content to prepare the DOM before the main fragment arrives. HTMX 4 also introduces the <hx-partial> element, which can target multiple elements in a single response and specify its own hx-target and hx-swap strategy.
Rizzy provides a component called HtmxSwappable along with a scoped service called HtmxSwapService to make this easier for you.
Out of Band Swapping
Please see "Out of Band Swapping" for full details