--- title: "hx-status" description: "Handles responses differently by status code" --- The `hx-status` attribute overrides swap behavior based on the HTTP response status code. ## Examples ```html
...
...
``` ## Patterns The status code goes after the colon: `hx-status:CODE="..."`. Supports exact codes, single-digit wildcards (`x`), and range wildcards (`xx`): ```html
...
``` Evaluated in order of specificity: exact match (`404`), then 2-digit wildcard (`50x`), then 1-digit wildcard (`5xx`). ## Modifiers The value takes space-separated `key:value` pairs. ```html
...
``` ### `swap` Swap style for this status code. See [`hx-swap` styles](/reference/attributes/hx-swap#styles) for values. ```html
``` ### `target` CSS selector for the swap target. Overrides [`hx-target`](/reference/attributes/hx-target). ```html
``` ### `select` CSS selector to pick content from the response. Overrides [`hx-select`](/reference/attributes/hx-select). ```html
``` ### `push` Push a URL to browser history. `true`/`false`, or a URL string. ```html
``` ### `replace` Replace the current URL in browser history. `true`/`false`, or a URL string. ```html
``` ### `transition` Use the [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API) for this swap. `true`/`false`. ```html
``` ## Notes * Values override response headers ([`HX-Retarget`](/reference/headers/HX-Retarget), [`HX-Reswap`](/reference/headers/HX-Reswap), [`HX-Reselect`](/reference/headers/HX-Reselect), etc.) * Without `hx-status`, htmx swaps all responses except [`204`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/204) and [`304`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304) ## See Also * [`hx-swap`](/reference/attributes/hx-swap) * [`hx-select`](/reference/attributes/hx-select) * [`hx-target`](/reference/attributes/hx-target) * [`htmx.config.noSwap`](/reference/config/htmx-config-noSwap)