htmx interview question · Most asked
What swap styles does hx-swap support?
Summary
innerHTML (the default, replace the target's content), outerHTML (replace the target), textContent, beforebegin, afterbegin, beforeend, afterend, delete (remove the target) and none (no swap, but response headers still apply). Modifiers add timing and scrolling: swap:300ms, settle:300ms, scroll:bottom, show:top, transition:true.
Longer Answer
Match the response to the swap: with beforeend the server returns only the new item; with outerHTML it returns the replacement element. The swap: delay keeps the old element with the htmx-swapping class so a CSS fade-out can run; transition:true uses the View Transitions API.
Key Points
- innerHTML default; outerHTML replaces the element.
- before/after begin/end insert.
- delete and none.
- Modifiers for timing, scrolling, transitions.
Deep dive: htmx Tutorial: Swapping: hx-swap
More most-asked htmx questions
- What security risks are specific to htmx, and how do you mitigate them?
- How does htmx compare with React or Vue?
- What is htmx?
- What do hx-get, hx-post, hx-put, hx-patch and hx-delete do, and how are values sent?
- What is hx-target, and what relative selectors does it support?
- How does hx-trigger work? Give examples of modifiers and special triggers.
- How do you handle form validation errors with htmx?
- Explain the htmx request lifecycle.