hx-preserveThe hx-preserve attribute allows you to keep an element unchanged during HTML replacement.
Elements with hx-preserve set are preserved by id when htmx updates any ancestor element.
You must set an unchanging id on elements for hx-preserve to work.
The response requires an element with the same id, but its type and other attributes are ignored.
hx-preserve is not inheritedhx-preserve="true" or use it as a boolean attribute with just hx-preserve<input type="text"> (focus and caret position are lost), iframes or certain types of videos. To tackle some of these cases we recommend the morphdom extension, which does a more elaborate DOM
reconciliationhx-preserve elements will also have their state preservednone with requests that could contain a hx-preserve element to avoid losing ithx-preserve can cause elements to be removed from their current location and relocated to a new location when swapping in a partial/oob response<div id="new_location">
Just relocated the video here
<div id="video" hx-preserve></div>
</div>
<div id="notify" hx-swap-oob="true">
Notification updated but keep the same retain
<div id="retain" hx-preserve></div>
</div>