Html

HTML & web

HTML element trees for BEAM SSR and shared views. Html.Events handlers are inert on the server (stripped from markup) and become real listeners after the JS client hydrates. Common tags (div, span, h1, a, ul, li, form, input, button, table, ...) and void tags (br, hr, img, ...) are available. Document-shell tags (html, head, body, title, style, meta, ...) live in Html.Document. Use main_ for the HTML main element so it does not clash with a module's main value.

Types

Html

type Html msg = Html

An HTML node parameterized by a message type (unused on the server).

Examples

welcome : Html msg
welcome =
    node "p" [] [ text "hi" ]

Values

text

text : String -> Html msg

A text node.

Examples

text "hello"

node

node : String -> List (Attribute msg) -> List (Html msg) -> Html msg

A custom element by tag name.

Examples

node "div" [] [ text "hi" ]

map

map : (a -> b) -> Html a -> Html b

Remap the message type of an HTML tree.

Examples

map Never (text "x")

toString

toString : Html msg -> String

Render HTML to a fragment string (no document wrapper).

Examples

toString (text "hi")

toDocument

toDocument : Html msg -> String

Render a full HTML document string.

Examples

toDocument (node "p" [] [ text "hi" ])