Debian Codegraph @

www/src/content/reference/01-attributes/15-hx-push-url.md

raw symbols SCIP
1 ---
2 title: "hx-push-url"
3 description: "Pushes the URL into browser history"
4 ---
5
6 The `hx-push-url` attribute allows you to push a URL into the
7 browser [location history](https://developer.mozilla.org/en-US/docs/Web/API/History_API).
8 This creates a new history entry, allowing navigation with the browser's back and forward buttons.
9 htmx snapshots the current DOM and saves it into its history cache, and restores from this cache on navigation.
10
11 ## Syntax
12
13 ```html
14 <div hx-get="/account" hx-push-url="true">Go to My Account</div>
15 ```
16
17 The possible values of this attribute are:
18
19 1. `true`, which pushes the fetched URL into history.
20 2. `false`, which disables pushing the fetched URL if it would otherwise be pushed due to inheritance or
21 [`hx-boost`](/reference/attributes/hx-boost).
22 3. A URL to be pushed into the location bar.
23 This may be relative or absolute, as per [
24 `history.pushState()`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState).
25
26 Here is an example:
27
28 ```html
29 <div hx-get="/account" hx-push-url="true">
30 Go to My Account
31 </div>
32 ```
33
34 This will cause htmx to snapshot the current DOM to `localStorage` and push the URL `/account' into the browser location
35 bar.
36
37 Another example:
38
39 ```html
40 <div hx-get="/account" hx-push-url="/account/home">
41 Go to My Account
42 </div>
43 ```
44
45 This will push the URL `/account/home' into the location history.
46
47 ## Notes
48
49 * The [`HX-Push-Url` response header](/reference/headers/HX-Push-Url) has similar behavior and can override this attribute.