Module Tw_html.At

Functions for creating HTML attributes.

val id : string -> attr

id "my-id" creates an id attribute.

Global attributes

val title : string -> attr

title "My Title" creates a title attribute.

val lang : string -> attr

lang "en" creates a lang attribute.

val dir : string -> attr

dir "ltr" creates a dir attribute.

val tabindex : int -> attr

tabindex 0 creates a tabindex attribute.

val contenteditable : bool -> attr

contenteditable true creates a contenteditable attribute.

val spellcheck : string -> attr

spellcheck value sets the spellcheck attribute. Use "true" or "false".

val onclick : string -> attr

onclick "..." creates an onclick attribute.

Event attributes

val onchange : string -> attr

onchange "..." creates an onchange attribute.

val oninput : string -> attr

oninput "..." creates an oninput attribute.

val onsubmit : string -> attr

onsubmit "..." creates an onsubmit attribute.

val type' : string -> attr

type' "text/css" creates a type attribute.

Form attributes

val value : string -> attr

value "..." creates a value attribute.

val name : string -> attr

name "description" creates a name attribute.

val placeholder : string -> attr

placeholder "..." creates a placeholder attribute.

val required : attr

The required attribute.

val disabled : attr

The disabled attribute.

val checked : attr

The checked attribute.

val readonly : attr

The readonly attribute.

val href : string -> attr

href "/path" creates an href attribute.

val target : string -> attr

target "_blank" creates a target attribute.

val rel : string -> attr

rel "stylesheet" creates a rel attribute.

val download : string -> attr

download "file.pdf" creates a download attribute.

val src : string -> attr

src "/image.png" creates a src attribute.

Media attributes

val alt : string -> attr

alt "description" creates an alt attribute for images.

val width : int -> attr

width 800 creates a width attribute.

val height : int -> attr

height 600 creates a height attribute.

val loading : string -> attr

loading "lazy" creates a loading attribute.

val charset : string -> attr

charset "utf-8" creates a charset attribute.

Meta attributes

val content : string -> attr

content "..." creates a content attribute.

val property : string -> attr

property "og:title" creates a property attribute.

val style : string -> attr

style "color:red;" creates a style attribute.

Style attribute

val datetime : string -> attr

datetime "2025-07-28" creates a datetime attribute.

Time attributes

val srcset : string -> attr

srcset "..." creates a srcset attribute for responsive images.

Image attributes

val sizes : string -> attr

sizes "..." creates a sizes attribute for responsive images.

val title' : string -> attr

title' "My Page" creates a title attribute for elements.

Additional attributes

val loading_lazy : attr

The loading="lazy" attribute.

val v : string -> string -> attr

v key value creates a generic key-value attribute.

val void : attr

void is an empty attribute that doesn't render.

val true' : string -> attr

true' key creates a boolean attribute with a "true" value.

val false' : string -> attr

false' key creates a boolean attribute with a "false" value.

val if' : bool -> attr -> attr

if' cond at is at if cond is true, otherwise returns a void attribute.

val if_some : attr option -> attr

if_some o is at if o is Some at and void if o is None.

val is_void : attr -> bool

is_void at is true if the attribute is void (won't render).

val to_pair : attr -> string * string

to_pair at returns the attribute as a (name, value) pair.

val of_pair : (string * string) -> attr

of_pair (n, v) creates an attribute from a (name, value) pair.

Additional HTML5 attributes

val accesskey : string -> attr

accesskey key sets keyboard shortcut.

val action : string -> attr

action url sets form action URL.

val autocomplete : string -> attr

autocomplete value sets autocomplete behavior.

val autofocus : attr

autofocus sets element to be focused on page load.

val cols : int -> attr

cols n sets textarea columns.

val colspan : int -> attr

colspan n sets table cell column span.

val defer : attr

defer defers script execution.

val draggable : bool -> attr

draggable b sets whether element is draggable.

val for' : string -> attr

for' id associates label with form element.

val hidden : attr

hidden hides the element.

val list : string -> attr

list id associates input with datalist.

val method' : string -> attr

method' m sets form HTTP method.

val media : string -> attr

media query sets media query for resources.

val popover : string -> attr

popover value sets popover behavior.

val popovertarget : string -> attr

popovertarget id sets popover target element.

val popovertargetaction : string -> attr

popovertargetaction action sets popover action.

val rows : int -> attr

rows n sets textarea rows.

val rowspan : int -> attr

rowspan n sets table cell row span.

val selected : attr

selected marks option as selected.

val wrap : string -> attr

wrap mode sets textarea wrap mode.

SVG Attributes

val fill_rule : [ `evenodd ] -> attr

fill_rule `evenodd sets the fill rule

val clip_rule : [ `evenodd ] -> attr

clip_rule `evenodd sets the clipping rule

val cx : int -> attr

cx n sets the center x coordinate

val cy : int -> attr

cy n sets the center y coordinate

val r : int -> attr

r n sets the radius

val view_box : string -> attr

view_box "0 0 20 20" sets the viewBox

val fill : string -> attr

fill "currentColor" sets the fill color

val stroke : string -> attr

stroke "currentColor" sets the stroke color

val stroke_width : string -> attr

stroke_width "2" sets the stroke width

val stroke_linecap : string -> attr

stroke_linecap "round" sets the stroke line cap

val stroke_linejoin : string -> attr

stroke_linejoin "round" sets the stroke line join

val x : string -> attr

x "10" sets the x coordinate

val y : string -> attr

y "10" sets the y coordinate

val rx : string -> attr

rx "5" sets the x radius for rounded rectangles

val d : string -> attr

d "M10 10 L20 20" sets the path data

val x1 : string -> attr

x1 "0" sets the first x coordinate

val y1 : string -> attr

y1 "0" sets the first y coordinate

val x2 : string -> attr

x2 "20" sets the second x coordinate

val y2 : string -> attr

y2 "20" sets the second y coordinate