Skip to content

API Reference ​

HTMX.HTMX Module
julia
HTMX

Lightweight 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 bytes

  • auto — convert arbitrary values to HTML response strings

  • @__str — string literal macro for HyperscriptString

  • md_to_node — Markdown string/AST → h.* nodes

source
HTMX.HyperscriptString Type
julia
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.

source
HTMX.Node Type
julia
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:

julia
node = h.div(class="container")
node("child text")   # returns a new Node; original is unchanged

During 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.

source
HTMX.Raw Type
julia
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

julia
h.div(Raw("<em>trusted markup</em>"))
h.script(Raw("console.log('trusted program')"))
source
HTMX.attrs Method
julia
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.

source
HTMX.auto Method
julia
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 to wrap

  • AbstractArray — elements are recursively auto'd and joined with newlines

  • Pair(content, id) — wrapped in an OOB-swap div with hx-swap-oob="true" (table elements like <tr> are additionally wrapped in <template> so HTMX can swap them past the browser's innerHTML parser)

  • Anything else — rendered via repr("text/html", x)

source
HTMX.children Method
julia
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.

source
HTMX.h Method
julia
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:

julia
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).

source
HTMX.md_to_node Method
julia
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

julia
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")))
source
HTMX.tag Method
julia
tag(n::Node) -> Symbol

The element name of n, e.g. :div for h.div(...).

source
HTMX.@__str Macro
julia
@__str "text"

Create a HyperscriptString literal. Equivalent to HyperscriptString("text").

source
You are viewing the dev branch. This branch may include code written with Claude Code with less human supervision. Only human-approved code is merged into main.