| 1 | --- |
| 2 | title: "htmx.config.prefix" |
| 3 | description: "Set a secondary attribute prefix" |
| 4 | --- |
| 5 | |
| 6 | The `htmx.config.prefix` option sets a secondary attribute prefix that htmx recognises in addition to the primary `hx-` prefix, which always works regardless of this setting. |
| 7 | |
| 8 | **Default:** `"data-hx-"` |
| 9 | |
| 10 | This means `data-hx-get`, `data-hx-target`, etc. work out of the box alongside `hx-get`, `hx-target`, etc. — matching the htmx 2 dual-attribute behaviour. |
| 11 | |
| 12 | When both prefixes are present on the same element, `hx-` wins. |
| 13 | |
| 14 | ## Disable the secondary prefix |
| 15 | |
| 16 | ```html |
| 17 | <meta name="htmx-config" content='{"prefix":""}'> |
| 18 | ``` |
| 19 | |
| 20 | ## Use a custom secondary prefix |
| 21 | |
| 22 | ```html |
| 23 | <meta name="htmx-config" content='{"prefix":"data-boost-"}'> |
| 24 | ``` |
| 25 | |
| 26 | Now both `hx-get` and `data-boost-get` are recognised. |
| 27 | |
| 28 | ## Important: Set via meta tag |
| 29 | |
| 30 | The prefix is read once during htmx initialisation. Setting it via JavaScript after the page has loaded will not apply correctly, as elements will already have been processed. |
| 31 | |
| 32 | Always configure the prefix using the meta tag: |
| 33 | |
| 34 | ```html |
| 35 | <meta name="htmx-config" content='{"prefix":"data-hx-"}'> |
| 36 | ``` |