Tw_htmlA library for building HTML documents programmatically.
This module provides a type-safe and declarative API for creating HTML elements and attributes. It is designed to be used for generating static HTML pages.
type tw = Tw.tType alias for Tailwind styles for convenience.
module At : sig ... endFunctions for creating HTML attributes.
val txt : string -> ttxt s creates a text node from string s.
val txtf : string list -> ttxtf ["a"; "b"] is equivalent to txt "ab".
val raw : string -> traw html creates a node from raw HTML string. Use with caution.
val rawf : string list -> trawf ["a"; "b"] is equivalent to raw "ab".
val empty : tempty is the empty element, equivalent to no content.
module Aria : sig ... endval to_string : ?doctype:bool -> t -> stringto_string ?doctype element converts HTML element to string representation. If doctype is true (default: false), includes the HTML5 doctype declaration.
val has_forms : t -> boolhas_forms t returns true if the HTML tree contains form elements (input, select, textarea) that benefit from the forms plugin base styles.
Complete HTML page with integrated CSS.
A page value represents a complete, self-contained HTML document with all required CSS automatically generated from the Tailwind utilities used in the HTML structure. This ensures consistency between your markup and styles without manual CSS management.
Design rationale: The type is abstract to enforce the invariant that the CSS contains exactly the styles needed for the HTML content. Direct construction would break this guarantee.
val page :
?lang:string ->
?meta:(string * string) list ->
?title:string ->
?charset:string ->
?tw_css:string ->
t list ->
t list ->
pagepage ?lang ?meta ?title ?charset ?tw_css head body generates a complete HTML page and its corresponding CSS.
lang defaults to "en"charset defaults to "utf-8"meta is a list of (name, content) pairs for meta tagstitle is the page titletw_css defaults to "tw.css" - the filename for the CSS, automatically included as a <link> tag in HTML headhead is additional content for the head sectionbody is the body contentThe HTML automatically includes a <link rel="stylesheet" href="{tw_css}"> tag. Use html to get the HTML string and css to get the CSS filename and stylesheet.
val html : page -> stringhtml page extracts the HTML string from a page result.
css page extracts the CSS filename and stylesheet from a page result.
module Livereload : sig ... endul ?at ?tw children is an unordered list element.
nav ?at ?tw children is a navigation element.
section ?at ?tw children is a section element.
article ?at ?tw children is an article element.
header ?at ?tw children is a header element.
footer ?at ?tw children is a footer element.
script ?at ?tw children is a script element.
root ?at ?tw children is the root <html> element of a document.
val void : tvoid is an empty void element.
option ?at ?tw children is an option element.
select ?at ?tw children is a select element.
dialog ?at ?tw children is a dialog element.
picture ?at ?tw children is a picture element.
template ?at ?tw children is a template element.
textarea ?at ?tw children is a textarea element.
button ?at ?tw children is a button element.
fieldset ?at ?tw children is a fieldset element.
legend ?at ?tw children is a legend element.
details ?at ?tw children is a details element.
summary ?at ?tw children is a summary element.
kbd ?at ?tw children is a keyboard input element.
strong ?at ?tw children is a strong element.
thead ?at ?tw children is a table head element.
tbody ?at ?tw children is a table body element.
tfoot ?at ?tw children is a table footer element.
th ?at ?tw children is a table header cell element.
td ?at ?tw children is a table data cell element.
dl ?at ?tw children is a description list element.
dt ?at ?tw children is a description term element.
dd ?at ?tw children is a description definition element.
blockquote ?at ?tw children is a blockquote element.
figure ?at ?tw children is a figure element.
figcaption ?at ?tw children is a figure caption element.
canvas ?at ?tw children is a canvas element.
iframe ?at ?tw children is an iframe element.
svg ?at ?tw children creates an SVG root element.
circle ?at ?tw children creates a circle element.
rect ?at ?tw children creates a rectangle element.
val pp : t -> stringpp t pretty-prints HTML element t.