package dream-html

  1. Overview
  2. Docs
On This Page
  1. Attributes
  2. Tags
Legend:
Library
Module
Module type
Parameter
Class
Class type

All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style. To disambiguate them, attributes have a _ (underscore) suffix.

Attributes

Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _. Most attributes are constructed by passing in a value of some type.

All string-valued attributes allow formatting (interpolation):

div [id "section-%d" section_id] []

Or plain strings:

p [id "toast"] []

Most boolean attributes are plain values and don't need to be constructed with function calls:

input [required]

However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:

div [contenteditable true] [
  p [] [txt "Edit me!"];
  p [contenteditable false] [txt "Can't edit me!"];
]

Enumerated attributes accept specific values:

input [inputmode `tel]
  • since 1.0.0.
type enctype = [
  1. | `urlencoded
  2. | `formdata
  3. | `text_plain
]
type method_ = [
  1. | `GET
  2. | `POST
  3. | `dialog
    (*
    • since 2.1.0
    *)
]
val null_ : attr

An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.

p [if should_show then null_ else style_ "display:none"] [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
  • deprecated See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
val allow : _ string_attr
val alt : _ string_attr
val async : attr
val autocapitalize : [< `off | `none | `on | `sentences | `words | `characters ] to_attr
val autocomplete : [< `off | `on | `name | `honorific_prefix | `given_name | `additional_name | `honorific_suffix | `nickname | `email | `username | `new_password | `current_password | `one_time_code | `organization_title | `organization | `street_address | `address_line1 | `address_line2 | `address_line3 | `address_level4 | `address_level3 | `address_level2 | `address_level1 | `country | `country_name | `postal_code | `cc_name | `cc_given_name | `cc_additional_name | `cc_family_name | `cc_number | `cc_exp | `cc_exp_month | `cc_exp_year | `cc_csc | `cc_type | `transaction_currency | `transaction_amount | `language | `bday | `bday_day | `bday_month | `bday_year | `sex | `tel | `tel_country_code | `tel_national | `tel_area_code | `tel_local | `tel_extension | `impp | `url | `photo | `webauthn ] to_attr
val autofocus : attr
val autoplay : attr
val buffered : _ string_attr
val capture : [< `user | `environment ] to_attr
val charset : _ string_attr
val checked : attr
val cite_ : _ string_attr
val class_ : _ string_attr
val color : _ string_attr
  • deprecated See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font#color
val cols : int to_attr
val colspan : int to_attr
val content : _ string_attr
val contenteditable : bool to_attr
val contextmenu : _ string_attr
val controls : attr
val coords : _ string_attr
val crossorigin : [< `anonymous | `use_credentials ] to_attr
val data_ : _ string_attr
val datetime : _ string_attr
val decoding : [< `sync | `async | `auto ] to_attr
val default : attr
val defer : attr
val dir : [< `ltr | `rtl | `auto ] to_attr
val dirname : _ string_attr
val disabled : attr
val download : _ string_attr
val draggable : attr
val enctype : [< enctype ] to_attr
val fetchpriority : [< `high | `low | `auto ] to_attr
  • since 1.2.0.
val for_ : _ string_attr
val form_ : _ string_attr
val formaction : _ string_attr
val formenctype : [< enctype ] to_attr
val formmethod : [< method_ ] to_attr
val formnovalidate : attr
val formtarget : _ string_attr
val headers : _ string_attr
val height : _ string_attr
val hidden : [< `hidden | `until_found ] to_attr
val high : float to_attr
val href : _ string_attr
val hreflang : _ string_attr
val http_equiv : [< `content_security_policy | `content_type | `default_style | `x_ua_compatible | `refresh ] to_attr
val id : _ string_attr
val integrity : _ string_attr
val inputmode : [< `none | `text | `decimal | `numeric | `tel | `search | `email | `url ] to_attr
val ismap : attr
val itemprop : _ string_attr
val kind : [< `subtitles | `captions | `descriptions | `chapters | `metadata ] to_attr
val label_ : _ string_attr
val lang : _ string_attr
val list : _ string_attr
val loading_lazy : attr

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#loading. loading=eager is the default so no need for specifically that value.

  • since 3.1.0.
val loop : attr
val low : float to_attr
val max : _ string_attr
val maxlength : int to_attr
val media : _ string_attr
val method_ : [< method_ ] to_attr
val min : _ string_attr
val minlength : int to_attr
val multiple : attr
val muted : attr
val name : _ string_attr
val novalidate : attr
val onblur : _ string_attr

Note that the value of this attribute is not escaped.

val onclick : _ string_attr

Note that the value of this attribute is not escaped.

val open_ : attr
val optimum : float to_attr
val pattern : _ string_attr
val ping : _ string_attr
val placeholder : _ string_attr
val playsinline : attr
val poster : _ string_attr
val preload : [< `none | `metadata | `auto ] to_attr
val readonly : attr
val referrerpolicy : [< `no_referrer | `no_referrer_when_downgrade | `origin | `origin_when_cross_origin | `same_origin | `strict_origin | `strict_origin_when_cross_origin | `unsafe_url ] to_attr
val rel : _ string_attr
val required : attr
val reversed : attr
val role : [ `alert | `alertdialog | `application | `article | `banner | `button | `cell | `checkbox | `columnheader | `combobox | `comment | `complementary | `contentinfo | `definition | `dialog | `document | `feed | `figure | `form | `generic | `grid | `gridcell | `group | `heading | `img | `link | `list | `listbox | `listitem | `log | `main | `mark | `marquee | `math | `menu | `menubar | `menuitem | `menuitemcheckbox | `menuitemradio | `meter | `navigation | `none | `note | `option | `presentation | `progressbar | `radio | `radiogroup | `region | `row | `rowgroup | `rowheader | `scrollbar | `search | `searchbox | `separator | `slider | `spinbutton | `status | `suggestion | `switch | `tab | `table | `tablist | `tabpanel | `term | `textbox | `timer | `toolbar | `tooltip | `tree | `treegrid | `treeitem ] to_attr
  • since 3.0.0
val rows : int to_attr
val rowspan : int to_attr
val sandbox : _ string_attr
val scope : _ string_attr
val selected : attr
val shape : _ string_attr
val sizes : _ string_attr
val slot_ : _ string_attr
val span_ : int to_attr
val spellcheck : bool to_attr
val src : _ string_attr
val srcdoc : _ string_attr
val srclang : _ string_attr
val srcset : _ string_attr
val start : int to_attr
val step : _ string_attr
val style_ : _ string_attr

Note that the value of this attribute is not escaped.

val tabindex : int to_attr
val target : _ string_attr
val title_ : _ string_attr
val translate : [< `yes | `no ] to_attr
val type_ : _ string_attr

Note: this can't be restricted to just the allowed values for <input type>, because it's used in other elements e.g. <link type>.

val usemap : _ string_attr
val value : _ string_attr
val width : _ string_attr
val wrap : [< `hard | `soft ] to_attr

Tags

HTML tags. Most (standard tags) are constructed by passing a list of attributes and a list of children:

div [id "my-div"] [p [] [txt "Hello"]]

Some (void elements) are constructed only with a list of attributes:

input [required; type_ "email"; name "email-addr"]

Finally, a few (text elements) are constructed with a list of attributes and a single format string child:

title [] "Document title"

title [] "My App ・ %s" page_name

script [] {|alert('Careful, this is not escaped :-)');|}
val null : node list -> node

A tag that will not be rendered in the markup. Useful for containing a bunch of child nodes inside a single node without having to litter the DOM with an actual node. Also may be called 'splicing'.

null [
  p [] [txt "This paragraph."];
  p [] [txt "And this paragraph."];
  p [] [txt "Are spliced directly into the document without a containing node."];
]

Also useful for constructing a completely empty node that is erased when printing:

null []
val a : std_tag
val address : std_tag
val area : void_tag
val abbr : std_tag
val article : std_tag
val aside : std_tag
val audio : std_tag
val b : std_tag
val base : void_tag
val bdi : std_tag
val bdo : std_tag
val blockquote : std_tag
val body : std_tag
val br : void_tag
val button : std_tag
val canvas : std_tag
val caption : std_tag
val cite : std_tag
val code : std_tag
val col : void_tag
val colgroup : std_tag
val data : std_tag
val datalist : std_tag
val dd : std_tag
val del : std_tag
val details : std_tag
val dfn : std_tag
val dialog : std_tag
val div : std_tag
val dl : std_tag
val dt : std_tag
val em : std_tag
val embed : void_tag
val fieldset : std_tag
val figcaption : std_tag
val figure : std_tag
val form : std_tag
val h1 : std_tag
val h2 : std_tag
val h3 : std_tag
val h4 : std_tag
val h5 : std_tag
val h6 : std_tag
val head : std_tag
val header : std_tag
val hgroup : std_tag
val hr : void_tag
val html : std_tag

A <!DOCTYPE html> declaration is automatically prefixed when this tag is printed.

val i : std_tag
val iframe : std_tag
val img : void_tag
val input : void_tag
val ins : std_tag
val kbd : std_tag
val label : std_tag
val legend : std_tag
val li : std_tag
val main : std_tag
val map : std_tag
val mark : std_tag
val menu : std_tag
val meta : void_tag
val meter : std_tag
val nav : std_tag
val noscript : std_tag
val object_ : std_tag
val ol : std_tag
val optgroup : std_tag
val option : _ text_tag
val output : std_tag
val p : std_tag
val picture : std_tag
val pre : std_tag
val progress : std_tag
val q : std_tag
val rp : std_tag
val rt : std_tag
val ruby : std_tag
val s : std_tag
val samp : std_tag
val script : _ text_tag

Note that the content of this tag is not escaped.

val section : std_tag
val select : std_tag
val slot : std_tag
val small : std_tag
val source : void_tag
val span : std_tag
val strong : std_tag
val style : _ text_tag

Note that the content of this tag is not escaped.

val sub : std_tag
val summary : std_tag
val sup : std_tag
val table : std_tag
val tbody : std_tag
val td : std_tag
val template : std_tag
val textarea : _ text_tag
val tfoot : std_tag
val th : std_tag
val thead : std_tag
val time : std_tag
val title : _ text_tag
val tr : std_tag
val track : void_tag
val u : std_tag
val ul : std_tag
val var : std_tag
val video : std_tag
val wbr : void_tag
OCaml

Innovation. Community. Security.