Table of Contents

Class HtmxV4Config

Namespace
Ramstack.HtmxToolkit.Configuration
Assembly
Ramstack.HtmxToolkit.dll

Represents the configuration for HTMX 4.x.

public sealed class HtmxV4Config : HtmxConfig
Inheritance
HtmxV4Config
Inherited Members

Constructors

HtmxV4Config()

Represents the configuration for HTMX 4.x.

public HtmxV4Config()

Properties

AllowEmptySwapAfterOob

Gets or sets a value indicating whether the main swap is performed when no content remains after processing out-of-band elements. The HTMX default is false.

[JsonPropertyName("allowEmptySwapAfterOOB")]
public bool? AllowEmptySwapAfterOob { get; set; }

Property Value

bool?

Remarks

Processed <hx-partial> elements suppress an empty main swap regardless of this setting. The swapEmpty modifier on hx-swap overrides either default. Nonempty main content is still swapped, and the Delete swap style always runs.

DefaultFocusScroll

Gets or sets a value indicating whether the focused element should be scrolled into view. The HTMX default is false and can be overridden using the focus-scroll swap modifier.

public bool? DefaultFocusScroll { get; set; }

Property Value

bool?

DefaultSettleDelay

Gets or sets the default settle delay in milliseconds. The HTMX default is 1.

public int? DefaultSettleDelay { get; set; }

Property Value

int?

DefaultSwap

Gets or sets the default swap style. The HTMX default is InnerHtml.

[JsonConverter(typeof(HtmxSwapJsonConverter))]
public HtmxSwap? DefaultSwap { get; set; }

Property Value

HtmxSwap?

DefaultTimeout

Gets or sets the default request timeout in milliseconds. The HTMX default is 60000.

public int? DefaultTimeout { get; set; }

Property Value

int?

Extensions

Gets or sets a comma-separated list of extensions that HTMX is allowed to register. The HTMX default is an empty string, which allows all extensions.

public string? Extensions { get; set; }

Property Value

string

Remarks

HTMX compares extension names exactly. Whitespace is allowed only after a comma; any other whitespace becomes part of a name, so "sse ,ws" does not allow sse.

History

Gets or sets how HTMX history restoration is handled. The HTMX default is Enabled.

[JsonConverter(typeof(HtmxHistoryModeJsonConverter))]
public HtmxHistoryMode? History { get; set; }

Property Value

HtmxHistoryMode?

ImplicitInheritance

Gets or sets a value indicating whether HTMX attributes are inherited implicitly. The HTMX default is false.

public bool? ImplicitInheritance { get; set; }

Property Value

bool?

IncludeIndicatorCss

Gets or sets a value indicating whether the indicator styles are loaded. The HTMX default is true.

[JsonPropertyName("includeIndicatorCSS")]
public bool? IncludeIndicatorCss { get; set; }

Property Value

bool?

IndicatorClass

Gets or sets the indicator class. The HTMX default is htmx-indicator.

public string? IndicatorClass { get; set; }

Property Value

string

InlineScriptNonce

Gets or sets the nonce added to inline scripts. The HTMX default is undefined, which means that no nonce is added.

public string? InlineScriptNonce { get; set; }

Property Value

string

LogAll

Gets or sets a value indicating whether all HTMX events are logged to the console. The HTMX default is false.

public bool? LogAll { get; set; }

Property Value

bool?

Mode

Gets or sets the request mode passed to the Fetch API. The HTMX default is SameOrigin.

[JsonConverter(typeof(HtmxFetchModeJsonConverter))]
public HtmxFetchMode? Mode { get; set; }

Property Value

HtmxFetchMode?

MorphIgnore

Gets or sets the attribute name prefixes to preserve during morphing. The HTMX default is ["data-htmx-powered"].

public string[]? MorphIgnore { get; set; }

Property Value

string[]

MorphScanLimit

Gets or sets the maximum number of siblings scanned while matching elements during morphing. The HTMX default is 10.

public int? MorphScanLimit { get; set; }

Property Value

int?

MorphSkip

Gets or sets the selector for elements to skip during morphing. The HTMX default is [hx-morph-skip].

public string? MorphSkip { get; set; }

Property Value

string

MorphSkipChildren

Gets or sets the selector for elements whose children should not be morphed. The HTMX default is [hx-morph-skip-children].

public string? MorphSkipChildren { get; set; }

Property Value

string

NoSwap

Gets or sets the response status codes or patterns for which HTMX does not perform a swap. The HTMX default is [204, 304].

public string[]? NoSwap { get; set; }

Property Value

string[]

Examples

options.UseHtmxV4(config =>
{
    // Keep the page unchanged on server errors, but still swap 4xx responses
    // such as 422 validation forms. Assigning the list replaces the HTMX default,
    // ["204", "304"], so the list repeats it.
    config.NoSwap = ["204", "304", "5xx"];
});

Remarks

Although HTMX declares this option as a number array, it converts each entry to a string at runtime and supports wildcard patterns such as "4xx" and "44x".

Prefix

Gets or sets the secondary attribute prefix recognized alongside hx-*. The HTMX default is data-hx-.

public string? Prefix { get; set; }

Property Value

string

RequestClass

Gets or sets the request class. The HTMX default is htmx-request.

public string? RequestClass { get; set; }

Property Value

string

Transitions

Gets or sets a value indicating whether the View Transition API should be used when swapping in new content. The HTMX default is false.

public bool? Transitions { get; set; }

Property Value

bool?

Methods

Serialize()

Serializes this configuration to a JSON string.

protected override string Serialize()

Returns

string

A JSON string representing this configuration.