Skip to main content

Elements and attributes

Build standard or custom markup with typed element builders, underscore-prefixed attributes, encoded text, and mixed attributes and children.

On this page

Overview

Build standard or custom markup with typed element builders, underscore-prefixed attributes, encoded text, and mixed attributes and children.

Elements

Open the static Html type to use standard HTML builders without qualification. Regular elements accept attributes and children; void elements accept attributes only.

open FSharp.ViewEngine
open type Html

article {
    h2 { "Account" }
    p { "Manage your profile." }
    input { _type "email"; _name "email" }
}

Attributes

Attribute helpers begin with an underscore, so they remain visually distinct from child elements. Boolean attributes render without a value.

button {
    _type "button"
    _class [ "button"; "button-primary" ]
    _disabled
    "Save"
}

Mixed content

Attributes, strings, and child elements can be yielded in one computation expression. Strings become encoded text nodes.

a {
    "Read "
    strong { "the guide" }
    _href "/guide"
    _class "guide-link"
}

Generic escape hatches

Use Html.el, Html.elVoid, and _attr for custom elements and attributes. Names are developer-controlled markup and are not validated.