htmx Cheat Sheet
Searchable reference of every hx-* attribute, htmx:* event, and HX-* header in htmx 2.0 with examples.
About This Tool
Wondering whether you should use hx-vals or hx-vars, or which response header triggers a client-side event? This cheat sheet puts every htmx 2.0 attribute, event, and header in one searchable place — with copy-ready HTML snippets, accepted values, and version notes for each entry.
htmx is a library that lets you build modern, interactive web UIs using HTML attributes alone. Instead of writing JavaScript to send requests and update the DOM, you sprinkle attributes like hx-get, hx-target, and hx-swap directly onto your markup. The server returns HTML fragments, htmx swaps them in place, and you get an SPA-like experience without the SPA complexity.
Entries are grouped into eight categories: Core Attributes (hx-get, hx-post, hx-put, hx-patch, hx-delete), Request Modifiers (hx-trigger, hx-vals, hx-headers, hx-include, hx-confirm, hx-disabled-elt, hx-sync, hx-indicator), Swap & Target (hx-target, hx-swap, hx-swap-oob, hx-select, hx-select-oob), Browser & History (hx-boost, hx-push-url, hx-replace-url, hx-history, hx-preserve), Events (htmx:beforeRequest, htmx:afterSwap, htmx:configRequest, plus the inline hx-on:* family), Request Headers (HX-Request, HX-Trigger, HX-Target, HX-Current-URL, HX-Prompt), Response Headers (HX-Trigger, HX-Redirect, HX-Refresh, HX-Reswap, HX-Retarget, HX-Reselect, HX-Push-Url, HX-Replace-Url, HX-Location), and Extensions (hx-ext, sse, ws).
Each entry shows the accepted values, a real HTML example, and the htmx version that introduced or changed it. The Quick Tips panel covers installation, trigger modifiers, swap styles, target selectors, the built-in CSS classes (.htmx-request, .htmx-indicator), common response patterns, CSRF tokens, and what changed between htmx 1.x and 2.0.
All processing happens entirely in your browser — there's no server-side filtering or analytics. The page works offline once loaded, so you can bookmark it as a permanent reference.
If you build server-rendered HTML you'll likely want our HTML Element Reference and CSS Selector Reference close at hand. For event-handler work, the JavaScript KeyCode Reference pairs nicely with htmx triggers like keyup. And when wiring up complex CSS in your htmx-swapped fragments, the Regex Cheat Sheet helps with pattern matching in attribute selectors.
How to Use
- Use the search bar at the top to find an attribute, event, or header by name (e.g., type "swap", "trigger", or "HX-Redirect").
- Click a category badge (Core Attributes, Events, Response Headers, etc.) to filter to one group at a time.
- Click any row to expand it and see the accepted values, an HTML example, and version notes.
- Click Copy next to the example to copy the snippet to your clipboard, or Copy name to copy just the attribute name.
- Toggle the Quick Tips panel for installation, trigger modifiers, swap styles, and the htmx 1.x vs 2.0 differences.
- Look for the version badge on each entry (e.g., 1.0+, 1.9+, 2.0) to confirm compatibility with your htmx version.
- Click "All" in the category filter to reset and show every entry again.
FAQ
What is htmx?
htmx is a small (~14 KB gzipped) JavaScript library that lets you build interactive web UIs using HTML attributes instead of writing JavaScript. You add attributes like hx-get, hx-target, and hx-swap to ordinary HTML elements; htmx intercepts events, sends AJAX requests, and swaps server-returned HTML fragments into the DOM. The result is an SPA-like experience driven entirely by your server-rendered HTML.
What's the difference between hx-get and hx-post?
Both issue AJAX requests when an element is triggered, but they use different HTTP methods. hx-get sends a GET request (idempotent, no body, parameters appended to the URL) — use it for fetching data, navigating, or refreshing a fragment. hx-post sends a POST request (non-idempotent, parameters in the body) — use it for forms, mutations, and any action that creates or modifies data. htmx also supports hx-put, hx-patch, and hx-delete for the corresponding REST verbs.
Is htmx 2.0 backwards compatible with htmx 1.x?
Mostly yes, but there are a few breaking changes. htmx 2.0 (released 2024) dropped IE11 support, removed the legacy hx-vars attribute (use hx-vals with the js: prefix instead), and split the single hx-on attribute into one attribute per event (e.g., hx-on:click, hx-on:htmx:after-request). It also tightened defaults — for example, non-anchor elements no longer get an implicit GET when only hx-* attributes are present. Most existing 1.x apps work without changes; check the official 2.0 migration guide for the full list.
Which hx-trigger events should I use?
The default trigger depends on the element: click for buttons and most elements, submit for forms, change for inputs and selects. You can override it with any DOM event name (keyup, change, focus, mouseenter, etc.) or htmx synthetic events (load, revealed, intersect). Add modifiers like 'changed' (only fire when value changes), 'delay:300ms' (debounce), 'throttle:500ms' (rate limit), 'from:#other' (listen on a different element), or 'every 5s' (polling). For search-as-you-type, the canonical pattern is hx-trigger="keyup changed delay:300ms".
What's the difference between hx-target and hx-swap?
hx-target selects which element receives the response (a CSS selector, or relative selectors like 'closest tr', 'find .body', 'next', 'previous'). hx-swap controls how the response is placed relative to the target — innerHTML replaces contents, outerHTML replaces the whole element, beforeend appends inside, beforebegin inserts before the element, delete removes the target, and none fires events without swapping. Used together they give you precise control over where and how content updates.
How do htmx response headers like HX-Trigger work?
The server can include HX-* headers in the response to control client-side behavior without writing JavaScript. HX-Trigger fires a client-side event (or events with detail data via JSON), HX-Redirect performs a full-page redirect, HX-Location performs a client-side htmx redirect, HX-Refresh reloads the page, HX-Push-Url updates browser history, and HX-Reswap/HX-Retarget/HX-Reselect override the swap configuration for that response. They're the bridge between your server logic and the htmx client.
Is my data safe?
Yes. This cheat sheet is a static reference rendered from a local dataset using client-side JavaScript only. No attribute names, search queries, or copied snippets ever leave your browser, and no analytics are tied to specific entries. The page works offline once loaded, so you can bookmark it as a permanent reference even on air-gapped machines.
Related Tools
HTML Element Reference
Complete HTML5 element reference organized by category with attributes, examples, and semantic usage guide.
CSS Selector Reference
Complete interactive CSS selector reference with specificity calculator, live preview, searchable categories, and browser support for every selector.
React Hooks Reference
Complete reference for all 18 React hooks with signatures, parameters, return values, code examples, common patterns, and gotchas.
Vim Cheat Sheet
Interactive Vim cheat sheet with search, mode and category filters. Browse 100+ Vim commands for Normal, Insert, Visual, and Command-line modes.
JavaScript KeyCode Reference
Press any key to see its event.key, keyCode, code, and which values. Searchable reference table for all keyboard events.
Regex Cheat Sheet
Interactive regex cheat sheet with searchable syntax reference, category filters, live pattern testing, and common regex patterns for JavaScript.