htmx 4.0 is under construction — migration guide

The htmx.config.defaultSwapEmpty option sets the default for whether htmx performs the main swap when the server returns an empty response body. It can be overridden per element with the swapEmpty modifier on hx-swap.

Default: unset. When unset, htmx performs the main swap on an empty response except when the response contained only <hx-partial> elements.

Values

  • true — perform the main swap on an empty response (clears the target)
  • false — skip the main swap on an empty response (leaves the target unchanged)

Example

htmx.config.defaultSwapEmpty = false;
<meta name="htmx-config" content='{"defaultSwapEmpty":false}'>

Override per element with the swapEmpty modifier on hx-swap:

<!-- skip the main swap on an empty response for this element only --> <div hx-swap="innerHTML swapEmpty:false"></div> <!-- force the main swap even on an empty response --> <div hx-swap="innerHTML swapEmpty:true"></div>