package tyxml

  1. Overview
  2. Docs
A library for building correct HTML and SVG documents


Dune Dependency






TyXML provides a set of convenient combinators that uses the OCaml type system to ensure the validity of the generated documents. TyXML can be used with any representation of HTML and SVG: the textual one, provided directly by this package, or DOM trees (js_of_ocaml-tyxml) virtual DOM (virtual-dom) and reactive or replicated trees (eliom). You can also create your own representation and use it to instantiate a new set of combinators.

Published: 04 Oct 2023



TyXML is a library for building statically correct HTML5 and SVG documents:

open Tyxml
let to_ocaml = Html.(a ~a:[a_href ""] [txt "OCaml!"])

Tyxml can also be used with the standard HTML syntax, using the PPX:

open Tyxml
let%html to_ocaml = "<a href=''>OCaml!</a>"

Finally, TyXML can be used with Reason's JSX syntax:

open Tyxml;
let to_reason = <a href=""> "Reason!" </a>

TyXML provides a set of combinators which use the OCaml type system to ensure the validity of the generated document. TyXML can be used on a wide variety of context, either to produce textual documents, to manipulate the DOM tree using Js_of_ocaml, build virtual DOM with virtual-dom, or for tierless web programming with Eliom.

The documentation can be consulted on the TyXML website. Examples are available in the examples directory.


TyXML is available in OPAM:

opam install tyxml

To install the PPX:

opam install tyxml-ppx

To install the JSX:

opam install tyxml-jsx

Dependencies (5)

  1. uutf >= "1.0.0"
  2. seq
  3. re >= "1.7.2"
  4. ocaml >= "4.04"
  5. dune >= "2.7"

Dev Dependencies (2)

  1. odoc with-doc
  2. alcotest with-test