HTMX Out-of-Band Swaps

OOB swaps allow you to update multiple parts of the page from a single response.

What are OOB Swaps?

Normally, HTMX swaps content into the element that triggered the request. OOB swaps let you update additional elements anywhere on the page.

Basic OOB Swap

<!-- This element will replace #notification wherever it exists -->
<div id="notification" hx-swap-oob="true">
  <p>Message sent successfully!</p>
</div>

Swap Strategies

StrategyDescription
true / outerHTMLReplace the entire element
innerHTMLReplace only the inner content
beforebeginInsert before the element
afterendInsert after the element
deleteRemove the element

SSE + OOB Example

// When a new message is added, update both the list and the count
export async function action(ctx) {
  const { content } = await ctx.json();
  ctx.db.run('INSERT INTO messages (content) VALUES (?)', [content]);
  
  // The SSE manager will send OOB swaps for:
  // - #message-list (new message)
  // - #message-count (updated count)
}