Attributes33 attributes
Requests
Attributes Requestshx-get | Issues GET request to specified URL |
|---|---|
Attributes Requestshx-post | Issues POST request to specified URL |
Attributes Requestshx-put | Issues PUT request to specified URL |
Attributes Requestshx-patch | Issues PATCH request to specified URL |
Attributes Requestshx-delete | Issues DELETE request to specified URL |
Request Control
Attributes Request Controlhx-trigger | Controls when element issues requests |
|---|---|
Attributes Request Controlhx-swap | Controls how response is inserted |
Attributes Request Controlhx-target | Controls where response is inserted |
Attributes Request Controlhx-select | Controls which response part is inserted |
Attributes Request Controlhx-swap-oob | Marks response elements to swap into page by ID |
Attributes Request Controlhx-select-oob | Picks response elements to swap into page by ID |
Attributes Request Controlhx-confirm | Shows confirmation dialog before request |
Scripting
Attributes Scriptinghx-on | Runs inline JavaScript when event fires |
|---|
Data
Attributes Datahx-vals | Adds values to request parameters |
|---|---|
Attributes Datahx-include | Includes additional element values in request |
Attributes Datahx-headers | Adds custom headers to request |
Attributes Datahx-encoding | Sets request encoding type |
History
Attributes Historyhx-push-url | Pushes URL into browser history |
|---|---|
Attributes Historyhx-replace-url | Replaces current URL in browser history |
Attributes Historyhx-history-elt | Marks element to swap on history restore |
Enhancements
Attributes Enhancementshx-boost | Converts links and forms to AJAX |
|---|---|
Attributes Enhancementshx-preload | Preloads content before user triggers request |
Attributes Enhancementshx-optimistic | Shows optimistic content during request |
Advanced
Attributes Advancedhx-indicator | Specifies loading indicator element |
|---|---|
Attributes Advancedhx-status | Handles responses differently by status code |
Attributes Advancedhx-sync | Synchronizes requests between elements |
Attributes Advancedhx-validate | Validates before submitting request |
Attributes Advancedhx-disable | Disables elements during request |
Attributes Advancedhx-ignore | Disables htmx processing for element |
Attributes Advancedhx-preserve | Preserves element during swaps |
Attributes Advancedhx-action | Specifies URL to receive request |
Attributes Advancedhx-method | Specifies HTTP method for request |
Attributes Advancedhx-config | Configures request behavior |
Headers16 headers
Request
Headers RequestHX-Request | Indicates request was made by htmx |
|---|---|
Headers RequestHX-Request-Type | Indicates partial or full page request |
Headers RequestHX-Current-URL | Contains browser URL when request started |
Headers RequestHX-Source | Identifies element that triggered the request |
Headers RequestHX-Target | Identifies element that will receive response |
Headers RequestHX-Boosted | Indicates boosted navigation request |
Headers RequestHX-History-Restore-Request | Indicates history navigation (back/forward) |
Response
Headers ResponseHX-Trigger | Triggers client-side events with htmx.trigger() |
|---|---|
Headers ResponseHX-Location | Navigates with htmx.ajax() |
Headers ResponseHX-Redirect | Redirects by setting location.href |
Headers ResponseHX-Refresh | Reloads page with location.reload() |
Headers ResponseHX-Retarget | Overrides swap target from server |
Headers ResponseHX-Reswap | Overrides swap style from server |
Headers ResponseHX-Reselect | Overrides content selection from server |
Headers ResponseHX-Replace-Url | Replaces current URL in browser history |
Headers ResponseHX-Push-Url | Pushes URL into browser history stack |
Events31 events
Request Lifecycle
Events Request Lifecyclehtmx:config:request | Fires before request data is encoded |
|---|---|
Events Request Lifecyclehtmx:confirm | Fires before handling hx-confirm |
Events Request Lifecyclehtmx:before:request | Fires immediately before fetch() |
Events Request Lifecyclehtmx:before:response | Fires after fetch(), before response.text() |
Events Request Lifecyclehtmx:after:request | Fires after response.text() |
Events Request Lifecyclehtmx:response:error | Fires for HTTP status 400 or higher |
Events Request Lifecyclehtmx:before:swap | Fires before DOM update |
Events Request Lifecyclehtmx:before:settle | Fires after DOM insertion, before settle tasks |
Events Request Lifecyclehtmx:after:settle | Fires after settle tasks |
Events Request Lifecyclehtmx:after:swap | Fires after DOM update |
Events Request Lifecyclehtmx:finally:request | Fires after lifecycle ends, including failures |
Events Request Lifecyclehtmx:error | Fires after request or swap exception |
Events Request Lifecyclehtmx:abort | Aborts in-flight request |
Elements
Events Elementshtmx:before:init | Fires before element initialization |
|---|---|
Events Elementshtmx:after:init | Fires after element initialization |
Events Elementshtmx:before:process | Fires before DOM node processing |
Events Elementshtmx:after:process | Fires after DOM node processing |
Events Elementshtmx:process:{type} | Fires during registered template processing |
Events Elementshtmx:after:implicitInheritance | Fires after implicit inheritance |
Events Elementshtmx:before:cleanup | Fires before element data removal |
Events Elementshtmx:after:cleanup | Fires after element data removal |
Events Elementsload | Fires after element initialization |
History
Events Historyhtmx:before:history:update | Fires before browser history update |
|---|---|
Events Historyhtmx:after:history:update | Fires after browser history update |
Events Historyhtmx:after:history:push | Fires after history push |
Events Historyhtmx:after:history:replace | Fires after history replacement |
Events Historyhtmx:before:history:restore | Fires before history restoration |
View Transitions
Events View Transitionshtmx:before:viewTransition | Fires before view transition starts |
|---|---|
Events View Transitionshtmx:after:viewTransition | Fires after view transition completes |
Triggers
Events Triggersintersect | Fires when element enters viewport |
|---|---|
Events Triggersevery | Fires at each polling interval |
Config24 config
Core
Config Corehtmx.config | Configures htmx behavior globally |
|---|---|
Config Corehtmx.version | Reports current htmx version (read-only) |
Config Corehtmx.config.prefix | Sets secondary attribute prefix |
Config Corehtmx.config.metaCharacter | Replaces : in attribute modifiers |
Config Corehtmx.config.extensions | Restricts extension registration by name |
Requests
Config Requestshtmx.config.defaultTimeout | Sets default request timeout in ms |
|---|---|
Config Requestshtmx.config.mode | Sets request mode for fetch() |
Swaps
Config Swapshtmx.config.defaultSwap | Sets default swap style for responses |
|---|---|
Config Swapshtmx.config.defaultSwapEmpty | Controls main swap when response body is empty |
Config Swapshtmx.config.noSwap | Sets HTTP status codes that skip swap |
Config Swapshtmx.config.transitions | Enables View Transitions API support |
Config Swapshtmx.config.defaultSettleDelay | Sets swap-to-settle delay in ms |
Config Swapshtmx.config.defaultFocusScroll | Scrolls to focused element after swap |
Morphing
Config Morphinghtmx.config.morphIgnore | Preserves attribute prefixes during morphing |
|---|---|
Config Morphinghtmx.config.morphSkip | Skips morphing for specific elements |
Config Morphinghtmx.config.morphSkipChildren | Skips morphing children of specific elements |
Config Morphinghtmx.config.morphScanLimit | Limits siblings scanned during morph matching |
Indicators
Config Indicatorshtmx.config.includeIndicatorCSS | Includes built-in loading indicator CSS |
|---|---|
Config Indicatorshtmx.config.indicatorClass | Sets class hidden by built-in indicator CSS |
Config Indicatorshtmx.config.requestClass | Sets class applied during requests |
Behavior
Config Behaviorhtmx.config.history | Controls htmx browser history management |
|---|---|
Config Behaviorhtmx.config.implicitInheritance | Enables implicit attribute inheritance |
Config Behaviorhtmx.config.inlineScriptNonce | Sets nonce on inline scripts generated by htmx |
Config Behaviorhtmx.config.logAll | Logs all htmx events to console |
Methods11 methods
Requests
Methods Requestshtmx.ajax() | Issues an htmx request |
|---|
DOM
Methods DOMhtmx.find() | Finds first matching element |
|---|---|
Methods DOMhtmx.findAll() | Finds all matching elements |
Methods DOMhtmx.process() | Processes htmx attributes on element |
Methods DOMhtmx.swap() | Swaps HTML content |
Events
Methods Eventshtmx.on() | Listens for htmx events |
|---|---|
Methods Eventshtmx.onLoad() | Executes callback when elements load |
Methods Eventshtmx.trigger() | Triggers custom events |
Extensions
Methods Extensionshtmx.registerExtension() | Registers htmx extension |
|---|
Timing
Methods Timinghtmx.parseInterval() | Parses time intervals to milliseconds |
|---|---|
Methods Timinghtmx.timeout() | Creates timeout Promise |
Tags1 tags
Tags <hx-partial> | Targets multiple elements with one response |
|---|