API Reference
HTMX.HTMX Module
HTMXLightweight HTML builder. Owns a small immutable HTML Node primitive and renders it to HTML and Markdown.
Exports
h— tag-based HTML node builder (h.div(...),h.p("text"))Node— immutable HTML node (tag/attrs/children)Raw— explicit wrapper for complete, trusted HTML/JS/CSS bytesauto— convert arbitrary values to HTML response strings@__str— string literal macro forHyperscriptStringmd_to_node— Markdown string/AST →h.*nodes
HTMX.HyperscriptString Type
HyperscriptString(s::AbstractString)A string subtype that, when passed as a child to a Node, is moved to the _ (hyperscript) HTML attribute instead of appearing as text content.
Multiple HyperscriptString children are concatenated with newlines in the _ attribute. Concatenation via * preserves the HyperscriptString type.
See also @__str for a literal constructor.
HTMX.Node Type
Node(tag, children...; attributes...)Immutable HTML node. Keyword arguments become HTML attributes (underscores are converted to hyphens, e.g. hx_get → hx-get). Attributes set to nothing or false are omitted; true renders as name="true" (browsers treat the quoted value as truthy). Positional arguments become children. An AbstractVector argument is flattened one level: its elements become children in order, so a long child list can be passed as one vector instead of splatted.
Use call syntax to append children or merge attributes:
node = h.div(class="container")
node("child text") # returns a new Node; original is unchangedDuring HTML rendering, HyperscriptString children are moved to the _ attribute (for hyperscript).
Ordinary child text and attribute values are HTML-escaped. Children that define their own show(::MIME"text/html", ...) method render structurally; wrap only complete, trusted literal markup or program text in Raw.
The fields are read with tag, attrs and children.
HTMX.Raw Type
Raw(html::AbstractString)Mark complete, trusted HTML/JS/CSS bytes for verbatim emission when used as an HTML Node child. Ordinary strings are escaped by default; use Raw only when the value is entirely server-owned and is already valid for its HTML context.
Raw does not disable attribute-value escaping. It is not a substitute for context-aware escaping of untrusted values interpolated into HTML, JavaScript, or CSS.
Example
h.div(Raw("<em>trusted markup</em>"))
h.script(Raw("console.log('trusted program')"))HTMX.attrs Method
attrs(n::Node) -> OrderedDict{Symbol,Any}The attributes of n, in insertion order, with hyphenated keys (:var"data-id"). The returned dictionary is the node's own field — copy it before mutating.
HTMX.auto Method
auto(x; wrap)Convert x to an HTML string, applying wrap to the result. wrap is mandatory — pass wrap=string (or wrap=identity) when calling directly; web frameworks built on top of HTMX.jl typically inject their own wrapper.
AbstractString— passed through towrapAbstractArray— elements are recursivelyauto'd and joined with newlinesPair(content, id)— wrapped in an OOB-swapdivwithhx-swap-oob="true"(table elements like<tr>are additionally wrapped in<template>so HTMX can swap them past the browser'sinnerHTMLparser)Anything else — rendered via
repr("text/html", x)
HTMX.children Method
children(n::Node) -> Vector{Any}The children of n, in document order. The returned vector is the node's own field — copy it before mutating.
HTMX.h Method
h(tag, children...; attributes...)
h.tag(children...; attributes...)Create an HTML Node. The property-access form h.div(...) is the standard way to build elements:
h.div(class="container")(
h.h1("Title"),
h.p("Paragraph")
)Keyword arguments become attributes (underscores → hyphens). Positional arguments become children. An AbstractVector argument is flattened one level: its elements become children in order, so a long child list can be passed as one vector instead of splatted. Attributes set to nothing or false are omitted; true renders as name="true" (browsers treat the quoted value as truthy).
HTMX.md_to_node Method
md_to_node(md)Convert a markdown string or Markdown.jl AST into h.* HTML nodes.
Inline math uses MathJax's \(...\) delimiters; display math (including fenced math blocks and standalone Markdown.LaTeX nodes) uses double-dollar delimiters. Formula text is HTML-escaped like other ordinary node children.
Example
md_to_node("**bold** and `code`")
md_to_node(Markdown.parse("**bold** and `code`"))
# both => h.div(h.p(h.strong("bold"), " and ", h.code("code")))HTMX.@__str Macro
@__str "text"Create a HyperscriptString literal. Equivalent to HyperscriptString("text").