</> htmx
🚧 htmx 4.0 is under construction. Read changes →

hx-include

The hx-include attribute allows you to include additional element values in an AJAX request. The value of this attribute can be:

Here is an example that includes a separate input value:

<div>
    <button hx-post="/register" hx-include="[name='email']">
        Register!
    </button>
    Enter email: <input name="email" type="email"/>
</div>

This is a little contrived as you would typically enclose both of these elements in a form and submit the value automatically, but it demonstrates the concept.

Note that you can also use the append modifier to add includes to inherited parent values:

<main hx-include:inherited="#hidden-input">
    ...
    <button hx-post="/example" hx-include:append="[name='email']">
        Post It!
    </button>
    Enter email: <input name="email" type="email"/>
</main>

Finally, note that if you include a non-input element, all input elements enclosed in that element will be included.

Notes

when working with the extended selectors such as find and closest.

<div hx-include="find input">
    <button hx-post="/register">
        Register!
    </button>
    Enter email: <input name="email" type="email"/>
</div>

In the above example, when clicking on the button, the find input selector is resolved from the button itself, which does not return any element here, since the button doesn’t have any input child, thus in this case, raises an error.