The htmx.config.defaultSwapEmpty option controls the main swap when the response body is empty.
Override it per element with swapEmpty.
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>