--- title: "hx-prompt" description: "Prompt before a request, send the answer as a header" category: "UX" icon: "icon-[mdi--comment-question-outline]" keywords: ["prompt", "input", "header", "hx-prompt", "htmx2"] --- The `hx-prompt` extension restores htmx 2's `hx-prompt` attribute. Before each request, it pops up a browser prompt. The answer becomes the `HX-Prompt` header. If the user cancels, the request never fires. ## Installing ```html ``` ## Usage ```html ``` On click: 1. Browser asks `Reason for deletion?`. 2. Cancel aborts. 3. Any answer (even empty) fires a cancelable [`htmx:prompt` event](#htmxprompt-event) carrying it in `event.detail.prompt`. 4. If nothing cancels it, htmx sends the request with the `HX-Prompt` header set to the answer. ### `htmx:prompt` event The `htmx:prompt` event fires on the source element after a valid answer. Listen with `hx-on::prompt` and call `event.preventDefault()` to abort: ```html ``` `event.detail` carries `{ prompt, target }`. `hx-on` exposes it directly, so they're in scope without unwrapping. ### Inheritance The `hx-prompt` attribute supports inheritance. ```html