Debian Codegraph @

www/src/content/extensions/01-htmx-2-compat.md

raw symbols SCIP
1 ---
2 title: "htmx-2-compat"
3 description: "Restore htmx 2.x defaults and event names on htmx 4"
4 category: "Compatibility"
5 icon: "icon-[mdi--backup-restore]"
6 keywords: ["compatibility", "migration", "htmx 2", "legacy"]
7 ---
8
9 The `htmx-2-compat` extension provides a compatibility layer that allows htmx 2.x code to run on htmx 4 with minimal changes. This is useful for gradual migration of existing applications.
10
11 ## Installing
12
13 ```html
14 <script src="https://cdn.jsdelivr.net/npm/htmx.org@__VERSION__/dist/htmx.min.js"></script>
15 <script src="https://cdn.jsdelivr.net/npm/htmx.org@__VERSION__/dist/ext/htmx-2-compat.js"></script>
16 ```
17
18 ## Usage
19
20 Once loaded, the extension maps old htmx 2.x APIs and behaviors to their htmx 4 equivalents, including:
21
22 - Old event names (e.g., `htmx:afterSwap` → [`htmx:after:swap`](/reference/events/htmx-after-swap))
23 - Implicit attribute inheritance (without requiring `:inherited` modifier)
24 - The `hx-ext` attribute for activating extensions
25 - Other htmx 2.x behaviors that changed in htmx 4
26
27 See the [Migration guide](/docs#migration) for a full list of changes between htmx 2.x and htmx 4.