
Error handling and status-specific swapping
Most InfoWorld readers will never have to face a 500 or a 404 error. But for those rare situations where a server returns an error code (yes, this is sarcasm), the new HTMX 4.0 behavior will be to swap in the content. Before, the request failed silently. This change will help developers provide immediate visual feedback to the user rather than leaving them with a broken or frozen screen.
The really cool part of this update is the new status-specific swapping syntax. You can now define different behaviors for different HTTP codes directly in the HTML. By using syntax like hx-status:404="#not-found" or hx-status:5xx="#error-notice", you can elegantly route different server errors to distinct UI elements.
The tag
The addition of is a major structural improvement. It allows you to wrap fragments in a response so they can target specific elements explicitly (e.g., ). It’s a cleaner, more readable alternative to the old “out-of-band” (OOB) swaps.

