You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[`hx-validate`](/reference/attributes/hx-validate)| Control form validation behavior |
@@ -1027,7 +1027,7 @@ Use different attributes for different operations:
1027
1027
<buttonhx-delete="/users/1">Delete User</button>
1028
1028
```
1029
1029
1030
-
Each attribute combines the URL and HTTP method.
1030
+
Each attribute combines the URL and HTTP method. Alternatively, use [`hx-action`](/reference/attributes/hx-action) and [`hx-method`](/reference/attributes/hx-method) to separate them — useful when the method is dynamic, or when you want progressive enhancement with native `action`/`method` fallback.
Copy file name to clipboardExpand all lines: www/src/content/reference/01-attributes/30-hx-action.md
+61-5Lines changed: 61 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "hx-action"
3
3
description: "Specifies the URL to receive the request"
4
4
---
5
5
6
-
The `hx-action` attribute specifies the URL that will receive the request.
6
+
The `hx-action` attribute specifies the URL that will receive the request. It mirrors the native `action` attribute on forms, making it familiar to HTML authors and enabling progressive enhancement.
7
7
8
8
## Syntax
9
9
@@ -13,22 +13,78 @@ The `hx-action` attribute specifies the URL that will receive the request.
13
13
</button>
14
14
```
15
15
16
+
## Progressive Enhancement
17
+
18
+
Like [`hx-boost`](/reference/attributes/hx-boost), `hx-action` supports progressive enhancement — the browser falls back to native `action`/`method` when JavaScript is unavailable. Where `hx-boost` provides page-navigation defaults (target body, scroll to top, push URL) for `<a>` and `<form>`, `hx-action` gives you full control over those behaviors and works on any element.
Unlike `hx-boost` (which always requests the same URL as the native `href`/`action`), `hx-action` can optionally point to a *different* URL. The recommended approach is still to detect htmx request headers and return fragments from the same URL, but in cases where separate endpoints are preferred, `hx-action` makes that possible:
hx-action="/fragments/contacts/new" <!-- separate partial endpoint -->
33
+
method="post"
34
+
hx-target="#contact-list">
35
+
<inputname="name"required>
36
+
<button>Create</button>
37
+
</form>
38
+
```
39
+
40
+
## Method Resolution
41
+
42
+
When `hx-action` is used without [`hx-method`](/reference/attributes/hx-method), htmx resolves the HTTP method using the same fallback chain browsers use:
43
+
44
+
1.[`hx-method`](/reference/attributes/hx-method) attribute on the element
45
+
2.`formmethod` attribute on the submitter button
46
+
3. Native `method` attribute on the form
47
+
4. Defaults to `GET`
48
+
49
+
This means submitter buttons with `formmethod` work as expected:
Copy file name to clipboardExpand all lines: www/src/content/reference/01-attributes/31-hx-method.md
+25-12Lines changed: 25 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "hx-method"
3
3
description: "Specifies the HTTP method for the request"
4
4
---
5
5
6
-
The `hx-method` attribute specifies the HTTP method (verb) to use for the request.
6
+
The `hx-method` attribute specifies the HTTP method (verb) to use for the request. It is typically paired with [`hx-action`](/reference/attributes/hx-action) to separate the URL from the method.
7
7
8
8
## Syntax
9
9
@@ -13,29 +13,42 @@ The `hx-method` attribute specifies the HTTP method (verb) to use for the reques
13
13
</button>
14
14
```
15
15
16
+
## Priority
17
+
18
+
`hx-method` takes the highest priority in the [method resolution chain](/reference/attributes/hx-action#method-resolution). It overrides both `formmethod` on submitter buttons and the native `method` attribute on forms:
19
+
20
+
```html
21
+
<!-- Always sends PUT regardless of native method or submitter -->
When `hx-method` is omitted, htmx falls back to `formmethod`, then native `method`, then `GET`. See [`hx-action` Method Resolution](/reference/attributes/hx-action#method-resolution) for the full chain.
* If no method can be determined from any source, defaults to `GET`
34
+
* The shorthand attributes [`hx-get`](/reference/attributes/hx-get), [`hx-post`](/reference/attributes/hx-post), etc. combine URL and method into one attribute
0 commit comments