Skip to content

HTML helpers

wybthon.html

html

Pythonic HTML element helpers that wrap h().

These helpers let you author markup that reads more like Python than hyperscript. Instead of writing:

h("div", {"class": "card", "on_click": handler}, h("p", {}, "Hello"))

you can write:

div(p("Hello"), class_="card", on_click=handler)

Children are positional arguments and props are keyword arguments.

Prop name mapping (Python keyword to HTML attribute):

  • class_class (the canonical reserved-word workaround).
  • html_forfor (Python reserved word).
  • All other kwargs pass through unchanged.

Each helper exported here (e.g. div, p, button, input_) is a thin wrapper that returns a VNode. Two element names collide with Python builtins, so they are exposed with a trailing underscore: main_ and input_.

See Also
  • h: the underlying hyperscript constructor.
  • Fragment: wrap a list of children with no DOM parent.

Functions:

Name Description
Fragment

Group multiple children without adding an extra DOM wrapper element.

Fragment

Fragment(*args: Any) -> VNode

Group multiple children without adding an extra DOM wrapper element.

Fragments use empty comment nodes as start/end markers and mount their children directly into the parent container. This avoids extra elements that would pollute selectors like :first-child or affect layout.

Parameters:

Name Type Description Default
*args Any

Either a sequence of children (Fragment(a, b, c)) or a single dict containing a children key (the form used when Fragment is called as h(Fragment, {}, a, b, c)).

()

Returns:

Type Description
VNode

A _fragment VNode that the reconciler will mount inline.

Example
Fragment(h1("Title"), p("Body text"))
h(Fragment, {}, h1("Title"), p("Body text"))  # same thing