htmx 4.0 is under construction — migration guide

hx-config

Configure request behavior with JSON

The hx-config attribute allows you to configure request behavior using JSON.

Syntax

<button hx-post="/api/users" hx-config='{"timeout": 5000}'> Create User </button>

Available Options

OptionTypeDescriptionExample
timeoutnumberRequest timeout in milliseconds5000
credentialsstringFetch credentials mode: “omit”, “same-origin”, “include""include”
modestringFetch mode: “cors”, “no-cors”, “same-origin""cors”
cachestringFetch cache mode: “default”, “no-cache”, “reload”, etc.”no-cache”
redirectstringFetch redirect mode: “follow”, “error”, “manual""follow”
referrerstringReferrer URL or “no-referrer""no-referrer”
integritystringSubresource integrity value”sha384-…”
validatebooleanWhether to validate form before submissiontrue

These options map to the Fetch API.

Merging Configuration

By default, child hx-config values replace parent configurations entirely. Use the + prefix to merge with parent config instead:

<div hx-config='{"timeout": 5000}'> <button hx-get="/data" hx-config='{"+headers": {"X-Custom": "value"}}'> Load Data </button> </div>

The button inherits the timeout and adds a custom header.

Without +, the child config replaces the parent config entirely.

Examples

Set timeout for slow endpoint

<button hx-get="/slow-report" hx-config='{"timeout": 30000}'> Generate Report </button>

Include credentials for CORS

<button hx-get="https://api.example.com/data" hx-config='{"credentials": "include", "mode": "cors"}'> Load External Data </button>

Disable cache

<button hx-get="/live-data" hx-config='{"cache": "no-cache"}'> Get Live Data </button>