Documentation
¶
Overview ¶
Package dot provides convenience wrappers for fluent HTML element constructors.
This package is designed to be used with Go's dot import feature, allowing you to write HTML generation code without package prefixes:
import (
. "github.com/jpl-au/fluent/dot"
"github.com/jpl-au/fluent/html5/meta"
)
func render() node.Node {
return Html(
Head(
meta.UTF8(),
Title().Text("My Page"),
Style().RawText("body { font-family: sans-serif; }"),
),
Body(
Div(
H1().Text("Welcome"),
P().Text("Hello, world!"),
).Class("container"),
),
)
}
Function Naming ¶
Each HTML element has a wrapper function matching its tag name:
- Div(children ...node.Node) - creates a <div> element
- H1(children ...node.Node) - creates an <h1> element
- etc.
Specialised constructors (like meta.UTF8()) require importing the element package directly.
Adding Content ¶
Use the .Text() method chain to add text content:
P().Text("Hello, world!")
H1().Class("title").Text("Welcome")
Style().RawText("body { color: red; }")
Content methods available:
- .Text(s) - adds escaped text content
- .Textf(format, args...) - adds formatted escaped text
- .Static(s) - adds static text (JIT-optimisable)
- .RawText(s) - adds unescaped HTML content
- .RawTextf(format, args...) - adds formatted unescaped HTML
Alternative: Package Imports ¶
If you prefer explicit package prefixes, import element packages directly:
import "github.com/jpl-au/fluent/html5/div"
el := div.New().Class("container").Text("Hello")
Index ¶
- func A(nodes ...node.Node) *a.Element
- func Abbr(nodes ...node.Node) *abbr.Element
- func Address(nodes ...node.Node) *address.Element
- func Area() *area.Element
- func Article(nodes ...node.Node) *article.Element
- func Aside(nodes ...node.Node) *aside.Element
- func Audio(nodes ...node.Node) *audio.Element
- func B(nodes ...node.Node) *b.Element
- func Base() *base.Element
- func Bdi(nodes ...node.Node) *bdi.Element
- func Bdo(nodes ...node.Node) *bdo.Element
- func Blockquote(nodes ...node.Node) *blockquote.Element
- func Body(nodes ...node.Node) *body.Element
- func Br() *br.Element
- func Button(nodes ...node.Node) *button.Element
- func Canvas(nodes ...node.Node) *canvas.Element
- func Caption(nodes ...node.Node) *caption.Element
- func Cite(nodes ...node.Node) *cite.Element
- func Code(nodes ...node.Node) *code.Element
- func Col() *col.Element
- func Colgroup(nodes ...node.Node) *colgroup.Element
- func Data(nodes ...node.Node) *data.Element
- func Datalist(nodes ...node.Node) *datalist.Element
- func Dd(nodes ...node.Node) *dd.Element
- func Del(nodes ...node.Node) *del.Element
- func Details(nodes ...node.Node) *details.Element
- func Dfn(nodes ...node.Node) *dfn.Element
- func Dialog(nodes ...node.Node) *dialog.Element
- func Div(nodes ...node.Node) *div.Element
- func Dl(nodes ...node.Node) *dl.Element
- func Dropdown(nodes ...node.Node) *dropdown.Element
- func Dt(nodes ...node.Node) *dt.Element
- func Em(nodes ...node.Node) *em.Element
- func Embed() *embed.Element
- func Fieldset(nodes ...node.Node) *fieldset.Element
- func Figcaption(nodes ...node.Node) *figcaption.Element
- func Figure(nodes ...node.Node) *figure.Element
- func Footer(nodes ...node.Node) *footer.Element
- func Form(nodes ...node.Node) *form.Element
- func H1(nodes ...node.Node) *h1.Element
- func H2(nodes ...node.Node) *h2.Element
- func H3(nodes ...node.Node) *h3.Element
- func H4(nodes ...node.Node) *h4.Element
- func H5(nodes ...node.Node) *h5.Element
- func H6(nodes ...node.Node) *h6.Element
- func Head(nodes ...node.Node) *head.Element
- func Header(nodes ...node.Node) *header.Element
- func Hgroup(nodes ...node.Node) *hgroup.Element
- func Hr() *hr.Element
- func Html(nodes ...node.Node) *html.Element
- func I(nodes ...node.Node) *i.Element
- func Iframe(nodes ...node.Node) *iframe.Element
- func Imagemap(nodes ...node.Node) *imagemap.Element
- func Img() *img.Element
- func Input() *input.Element
- func Ins(nodes ...node.Node) *ins.Element
- func Kbd(nodes ...node.Node) *kbd.Element
- func Label(nodes ...node.Node) *label.Element
- func Legend(nodes ...node.Node) *legend.Element
- func Li(nodes ...node.Node) *li.Element
- func Link() *link.Element
- func Mark(nodes ...node.Node) *mark.Element
- func Math(nodes ...node.Node) *math.Element
- func Menu(nodes ...node.Node) *menu.Element
- func Meta() *meta.Element
- func Meter(nodes ...node.Node) *meter.Element
- func Nav(nodes ...node.Node) *nav.Element
- func Noscript(nodes ...node.Node) *noscript.Element
- func Object(nodes ...node.Node) *object.Element
- func Ol(nodes ...node.Node) *ol.Element
- func Optgroup(nodes ...node.Node) *optgroup.Element
- func Option(nodes ...node.Node) *option.Element
- func Output(nodes ...node.Node) *output.Element
- func P(nodes ...node.Node) *p.Element
- func Picture(nodes ...node.Node) *picture.Element
- func Pre(nodes ...node.Node) *pre.Element
- func Primary(nodes ...node.Node) *primary.Element
- func Progress(nodes ...node.Node) *progress.Element
- func Q(nodes ...node.Node) *q.Element
- func Rp(nodes ...node.Node) *rp.Element
- func Rt(nodes ...node.Node) *rt.Element
- func Ruby(nodes ...node.Node) *ruby.Element
- func S(nodes ...node.Node) *s.Element
- func Samp(nodes ...node.Node) *samp.Element
- func Script(nodes ...node.Node) *script.Element
- func Search(nodes ...node.Node) *search.Element
- func Section(nodes ...node.Node) *section.Element
- func Slot(nodes ...node.Node) *slot.Element
- func Small(nodes ...node.Node) *small.Element
- func Source() *source.Element
- func Span(nodes ...node.Node) *span.Element
- func Strong(nodes ...node.Node) *strong.Element
- func Style(nodes ...node.Node) *style.Element
- func Sub(nodes ...node.Node) *sub.Element
- func Summary(nodes ...node.Node) *summary.Element
- func Sup(nodes ...node.Node) *sup.Element
- func Svg(nodes ...node.Node) *svg.Element
- func Table(nodes ...node.Node) *table.Element
- func Tbody(nodes ...node.Node) *tbody.Element
- func Td(nodes ...node.Node) *td.Element
- func Template(nodes ...node.Node) *template.Element
- func Textarea(nodes ...node.Node) *textarea.Element
- func Tfoot(nodes ...node.Node) *tfoot.Element
- func Th(nodes ...node.Node) *th.Element
- func Thead(nodes ...node.Node) *thead.Element
- func Time(nodes ...node.Node) *time.Element
- func Title(nodes ...node.Node) *title.Element
- func Tr(nodes ...node.Node) *tr.Element
- func Track() *track.Element
- func U(nodes ...node.Node) *u.Element
- func Ul(nodes ...node.Node) *ul.Element
- func Variable(nodes ...node.Node) *variable.Element
- func Video(nodes ...node.Node) *video.Element
- func Wbr() *wbr.Element
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func A ¶
A Creates a new anchor element without any initial attributes. Example: a.New(text.Text("Click here")).Href("https://example.com") Renders: <a href="https://example.com">Click here</a>
func Abbr ¶
Abbr Creates a new abbreviation element without any initial attributes. Use for basic abbreviations where semantic markup is needed. Example: abbr.New() Renders: <abbr></abbr>
func Address ¶
Address Creates a new address element without any initial attributes. Use for basic contact information where semantic markup is needed. Example: address.New() Renders: <address></address>
func Area ¶
Area Creates a new area element without any initial attributes. Example: area.New() Renders: <area />
func Article ¶
Article Creates a new article element with optional child nodes Example: article.New() Renders: <article></article>
func Aside ¶
Aside Creates a new aside element with the given child nodes. Example: aside.New() Renders: <aside></aside>
func Audio ¶
Audio Creates a new audio element without any initial attributes. Example: audio.New() Renders: <audio></audio>
func B ¶
B Creates a new b element with the given child nodes. Example: b.New(text.Text("This text is important.")) Renders: <b>This text is important.</b>
func Base ¶
Base Creates a new base element without any initial attributes. Example: base.New().Href("/docs/") Renders: <base href="/docs/" />
func Bdi ¶
Bdi Creates a new bdi element with the given child nodes. Example: bdi.New(text.Text("username")) Renders: <bdi>username</bdi>
func Bdo ¶
Bdo Creates a new bdo element with child nodes. Example: bdo.New(text.Text("Hello")) Renders: <bdo>Hello</bdo>
func Blockquote ¶
func Blockquote(nodes ...node.Node) *blockquote.Element
Blockquote Creates a new blockquote element with the given child nodes. Example: blockquote.New(p.Text("To be or not to be.")) Renders: <blockquote><p>To be or not to be.</p></blockquote>
func Body ¶
Body Creates a new body element with the given child nodes. Example: body.New(p.New(text.Text("Hello, World!"))) Renders: <body><p>Hello, World!</p></body>
func Br ¶
Br Creates a new br element without any initial attributes. Example: br.New() Renders: <br />
func Button ¶
Button Creates a new button element with the given child nodes. Example: button.New(text.Text("Click Me")) Renders: <button>Click Me</button>
func Canvas ¶
Canvas Creates a new canvas element with child nodes for fallback content. Example: canvas.New(text.Text("Your browser does not support canvas.")) Renders: <canvas>Your browser does not support canvas.</canvas>
func Caption ¶
Caption Creates a new caption element with the given child nodes. Example: caption.New(text.Text("My Table Caption")) Renders: <caption>My Table Caption</caption>
func Cite ¶
Cite Creates a new cite element with the given child nodes. Example: cite.New(text.Text("Nineteen Eighty-Four")) Renders: <cite>Nineteen Eighty-Four</cite>
func Code ¶
Code Creates a new code element with the given child nodes. Example: code.New(text.Text("console.log('Hello, World!');")) Renders: <code>console.log('Hello, World!');</code>
func Col ¶
Col Creates a new col element without any initial attributes. Example: col.New() Renders: <col />
func Colgroup ¶
Colgroup Creates a new colgroup element with the given child nodes (typically <col> elements). Example: colgroup.New(col.New(), col.Span(2)) Renders: <colgroup><col /><col span="2" /></colgroup>
func Data ¶
Data Creates a new data element with the given child nodes. Example: data.New(text.Text("Mini Ketchup")) Renders: <data>Mini Ketchup</data>
func Datalist ¶
Datalist Creates a new datalist element with child nodes (typically <option> elements). Example: datalist.New(option.New().Value("Chocolate"), option.New().Value("Vanilla")) Renders: <datalist><option value="Chocolate"><option value="Vanilla"></datalist>
func Dd ¶
Dd Creates a new dd element with child nodes. Example: dd.New(text.Text("A large feline inhabiting Bodmin Moor.")) Renders: <dd>A large feline inhabiting Bodmin Moor.</dd>
func Del ¶
Del Creates a new del element with optional child nodes. Example: del.New() Renders: <del></del>
func Details ¶
Details Creates a new details element with the given child nodes. Example: details.New(summary.Text("Details"), p.Text("Hidden content")) Renders: <details><summary>Details</summary><p>Hidden content</p></details>
func Dfn ¶
Dfn Creates a new dfn element with the given child nodes. Example: dfn.New(text.Text("validator")) Renders: <dfn>validator</dfn>
func Dialog ¶
Dialog Creates a new dialog element with the given child nodes. Example: dialog.New(p.Text("Greetings, one and all!")) Renders: <dialog><p>Greetings, one and all!</p></dialog>
func Div ¶
Div Creates a new div element with child nodes. Example: div.New(p.New(text.Text("Any kind of content here."))) Renders: <div><p>Any kind of content here.</p></div>
func Dl ¶
Dl Creates a new dl element with the given child nodes (typically <dt> and <dd> elements). Example: dl.New(dt.New(text.Text("Term")), dd.New(text.Text("Description"))) Renders: <dl><dt>Term</dt><dd>Description</dd></dl>
func Dropdown ¶
Dropdown Creates a new select element with option and optgroup child elements. Example: dropdown.New(option.Option("Red", "red"), option.Option("Blue", "blue")) Renders: <select><option value="red">Red</option><option value="blue">Blue</option></select>
func Dt ¶
Dt Creates a new dt element with the given child nodes. Example: dt.New(text.Text("Term")) Renders: <dt>Term</dt>
func Em ¶
Em Creates a new em element with the given child nodes. Example: em.New(text.Text("now")) Renders: <em>now</em>
func Embed ¶
Embed Creates a new embed element without any initial attributes. Example: embed.New() Renders: <embed />
func Fieldset ¶
Fieldset Creates a new fieldset element with child nodes. Example: fieldset.New(legend.Text("Personal details"), input.Text("name", "")) Renders: <fieldset><legend>Personal details</legend><input name="name" type="text" /></fieldset>
func Figcaption ¶
func Figcaption(nodes ...node.Node) *figcaption.Element
Figcaption Creates a new figcaption element with child nodes. Example: figcaption.New(text.Text("An elephant at sunset")) Renders: <figcaption>An elephant at sunset</figcaption>
func Figure ¶
Figure Creates a new figure element with the given child nodes. Example: figure.New(img.New().Src("elephant.jpg"), figcaption.New(text.Text("An elephant at sunset"))) Renders: <figure><img src="elephant.jpg" /><figcaption>An elephant at sunset</figcaption></figure>
func Footer ¶
Footer Creates a new footer element with the given child nodes. Example: footer.New(p.New(text.Text("Copyright 2023 My Website"))) Renders: <footer><p>Copyright 2023 My Website</p></footer>
func Form ¶
Form Creates a new form element with child nodes. Example: form.New(input.Text("name", ""), button.Submit("Send")) Renders: <form><input name="name" type="text" /><button type="submit">Send</button></form>
func H1 ¶
H1 Creates a new h1 element with the given child nodes. Example: h1.New(text.Text("Page Title")) Renders: <h1>Page Title</h1>
func H2 ¶
H2 Creates a new h2 element with the given child nodes. Example: h2.New(text.Text("Section Title")) Renders: <h2>Section Title</h2>
func H3 ¶
H3 Creates a new h3 element with the given child nodes. Example: h3.New(text.Text("Subsection Title")) Renders: <h3>Subsection Title</h3>
func H4 ¶
H4 Creates a new h4 element with the given child nodes. Example: h4.New(text.Text("Detailed Point")) Renders: <h4>Detailed Point</h4>
func H5 ¶
H5 Creates a new h5 element with the given child nodes. Example: h5.New(text.Text("Sub-point")) Renders: <h5>Sub-point</h5>
func H6 ¶
H6 Creates a new h6 element with the given child nodes. Example: h6.New(text.Text("Footnote Title")) Renders: <h6>Footnote Title</h6>
func Head ¶
Head Creates a new head element with the given child nodes (metadata content). Example: head.New(title.New(text.Text("My Page")), meta.Charset("UTF-8")) Renders: <head><title>My Page</title><meta charset="UTF-8" /></head>
func Header ¶
Header Creates a new header element with the given child nodes. Example: header.New(h1.Text("Welcome"), p.Text("A brief introduction")) Renders: <header><h1>Welcome</h1><p>A brief introduction</p></header>
func Hgroup ¶
Hgroup Creates a new hgroup element with child nodes (typically a heading and subtitle paragraphs). Example: hgroup.New(h1.Text("Main Title"), p.Text("A subtitle")) Renders: <hgroup><h1>Main Title</h1><p>A subtitle</p></hgroup>
func Hr ¶
Hr Creates a new hr element without any initial attributes. Example: hr.New() Renders: <hr />
func Html ¶
Html Creates a complete HTML5 document with DOCTYPE declaration Example: html.New() Renders: <!DOCTYPE html><html></html>
func I ¶
I Creates a new italic element with optional child nodes. Example: i.New() Renders: <i></i>
func Iframe ¶
Iframe Creates a new iframe element with optional fallback content. Example: iframe.New().Src("/page.html") Renders: <iframe src="/page.html"></iframe>
func Imagemap ¶
Imagemap Creates a new map element with optional child nodes (typically area elements). Example: imagemap.New(area.Rect(0, 0, 100, 50, "/page1")) Renders: <map><area shape="rect" coords="0,0,100,50" href="/page1" /></map>
func Img ¶
Img Creates a new img element without any initial attributes. Example: img.New().Src("photo.jpg").Alt("A beautiful sunset") Renders: <img src="photo.jpg" alt="A beautiful sunset" />
func Input ¶
Input Creates a new input element without any initial attributes. Example: input.New().Type(inputtype.Text).Name("username") Renders: <input name="username" type="text" />
func Ins ¶
Ins Creates a new ins element with optional child nodes. Example: ins.New() Renders: <ins></ins>
func Kbd ¶
Kbd Creates a new kbd element with optional child nodes. Example: kbd.New() Renders: <kbd></kbd>
func Label ¶
Label Creates a new label element with child nodes. Example: label.New() Renders: <label></label>
func Legend ¶
Legend Creates a new legend element with optional child nodes. Example: legend.New() Renders: <legend></legend>
func Li ¶
Li Creates a new list item element with optional child nodes. Example: li.New() Renders: <li></li>
func Link ¶
Link Creates a new link element without any initial attributes. Example: link.New() Renders: <link />
func Mark ¶
Mark Creates a new mark element with the given child nodes. Example: mark.New(text.Text("highlighted text")) Renders: <mark>highlighted text</mark>
func Math ¶
Math Creates a new math element with optional child nodes. Example: math.New() Renders: <math></math>
func Menu ¶
Menu Creates a new menu element with child li elements. Example: menu.New(li.Text("Cut"), li.Text("Copy"), li.Text("Paste")) Renders: <menu><li>Cut</li><li>Copy</li><li>Paste</li></menu>
func Meta ¶
Meta Creates a new meta element without any initial attributes. Example: meta.New() Renders: <meta />
func Meter ¶
Meter Creates a new meter element with optional child nodes Example: meter.New() Renders: <meter></meter>
func Nav ¶
Nav Creates a new nav element with optional child nodes Example: nav.New() Renders: <nav></nav>
func Noscript ¶
Noscript Creates a new noscript element with optional child nodes Example: noscript.New() Renders: <noscript></noscript>
func Object ¶
Object Creates a new object element with optional child nodes Example: object.New() Renders: <object></object>
func Ol ¶
Ol Creates a new ordered list element with optional child nodes (typically li elements) Example: ol.New() Renders: <ol></ol>
func Optgroup ¶
Optgroup Creates a new optgroup element with child option elements. Example: optgroup.New(option.Option("red", "Red"), option.Option("blue", "Blue")).Label("Colours") Renders: <optgroup label="Colours"><option value="red">Red</option><option value="blue">Blue</option></optgroup>
func Option ¶
Option Creates a new option element with optional child nodes Example: option.New() Renders: <option></option>
func Output ¶
Output Creates a new output element with optional child nodes Example: output.New() Renders: <output></output>
func P ¶
P Creates a new paragraph element with optional child nodes Example: p.New(text.Text("Hello")) Renders: <p>Hello</p>
func Picture ¶
Picture Creates a new picture element with source and img child elements. Example: picture.New(source.ImageWebP("photo.webp"), img.Src("photo.jpg")) Renders: <picture><source srcset="photo.webp" type="image/webp"><img src="photo.jpg"></picture>
func Pre ¶
Pre Creates a new pre element with the given child nodes Example: pre.New(text.Text("Code")) Renders: <pre>Code</pre>
func Primary ¶
Primary Creates a new main element with optional child nodes Example: primary.New() Renders: <main></main>
func Progress ¶
Progress Creates a new progress element with optional child nodes for fallback content. Example: progress.New() Renders: <progress></progress>
func Q ¶
Q Creates a new q element with optional child nodes. Example: q.New(text.Text("To be or not to be")) Renders: <q>To be or not to be</q>
func Rp ¶
Rp Creates a new rp element with optional child nodes. Example: rp.New(text.Text("(")) Renders: <rp>(</rp>
func Rt ¶
Rt Creates a new rt element with optional child nodes Example: rt.New(text.Text("kan")) Renders: <rt>kan</rt>
func Ruby ¶
Ruby Creates a new ruby element with optional child nodes Example: ruby.New(text.Text("漢字")) Renders: <ruby>漢字</ruby>
func S ¶
S Creates a new s element with optional child nodes. Examples: s.New() renders <s></s> s.New(text.Text("Old price: $100")) renders <s>Old price: $100</s>
func Samp ¶
Samp Creates a new samp element with optional child nodes Example: samp.New(text.Text("Output")) Renders: <samp>Output</samp>
func Script ¶
Script Creates a new script element without any initial attributes Example: script.New() Renders: <script></script>
func Search ¶
Search Creates a new search element with optional child nodes Example: search.New() Renders: <search></search>
func Section ¶
Section Creates a new section element with optional child nodes Example: section.New() Renders: <section></section>
func Slot ¶
Slot Creates a new slot element with optional child nodes. Example: slot.New() Renders: <slot></slot>
func Small ¶
Small Creates a new small element with the given child nodes. Example: small.New(text.Text("© 2024 Company Name")) Renders: <small>© 2024 Company Name</small>
func Source ¶
Source Creates a new source element without any initial attributes. Example: source.New().Src("image.webp").Type("image/webp") Renders: <source src="image.webp" type="image/webp" />
func Span ¶
Span Creates a new span element with optional child nodes. Example: span.New() Renders: <span></span>
func Strong ¶
Strong Creates a new strong element with optional child nodes. Example: strong.New() Renders: <strong></strong>
func Style ¶
Style Creates a new style element without any initial attributes. Example: style.New() Renders: <style></style>
func Sub ¶
Sub Creates a new sub element with the given child nodes. Example: sub.New(text.Text("2")) Renders: <sub>2</sub>
func Summary ¶
Summary Creates a new summary element with optional child nodes. Example: summary.New() Renders: <summary></summary>
func Sup ¶
Sup Creates a new sup element with the given child nodes. Example: sup.New(text.Text("2")) Renders: <sup>2</sup>
func Svg ¶
Svg Creates a new svg element with child SVG elements. Example: svg.New().Width("100").Height("100").ViewBox("0 0 100 100") Renders: <svg width="100" height="100" viewBox="0 0 100 100"></svg>
func Table ¶
Table Creates a new table element with optional child nodes (typically thead, tbody, tfoot, tr elements). Example: table.New() Renders: <table></table>
func Tbody ¶
Tbody Creates a new tbody element with child tr elements. Example: tbody.New(tr.New(td.Text("cell"))) Renders: <tbody><tr><td>cell</td></tr></tbody>
func Td ¶
Td Creates a new table data cell element with optional child nodes. Example: td.New() Renders: <td></td>
func Template ¶
Template Creates a new template element with child nodes. Content is not rendered directly but can be instantiated at runtime using JavaScript. Example: template.New() Renders: <template></template>
func Textarea ¶
Textarea Creates a new textarea element with optional child nodes Example: textarea.New() Renders: <textarea></textarea>
func Tfoot ¶
Tfoot Creates a new tfoot element with child tr elements. Example: tfoot.New(tr.New(td.Text("Total"), td.Text("100"))) Renders: <tfoot><tr><td>Total</td><td>100</td></tr></tfoot>
func Th ¶
Th Creates a new th element with optional child nodes. Example: th.New() Renders: <th></th>
func Thead ¶
Thead Creates a new thead element with child tr elements. Example: thead.New(tr.New(th.Text("Name"), th.Text("Age"))) Renders: <thead><tr><th>Name</th><th>Age</th></tr></thead>
func Time ¶
Time Creates a new time element with optional child nodes Example: time.New() Renders: <time></time>
func Title ¶
Title Creates a new title element with text content Example: title.New() Renders: <title></title>
func Tr ¶
Tr Creates a new table row element with optional child nodes (typically td or th elements). Example: tr.New() Renders: <tr></tr>
func Track ¶
Track Creates a new track element without any initial attributes. Example: track.New() Renders: <track />
func U ¶
U Creates a new u element with the given child nodes. Example: u.New(text.Text("misspelled"))
func Ul ¶
Ul Creates a new unordered list element with optional child nodes (typically li elements). Example: ul.New() Renders: <ul></ul>
func Variable ¶
Variable Creates a new var element with optional child nodes. Example: variable.New() Renders: <var></var>
Types ¶
This section is empty.