Documentation

Elements

The lib/elements package provides one function per HTML tag. Every function takes a WebComponent and returns an HTML string.

The lib/elements package provides one function per HTML tag. Every function takes a WebComponent and returns an HTML string.

WebComponent

type WebComponent struct {
    Class      string
    Attributes map[string]string
    Children   []any
    Text       string
}
FieldDescription
ClassValue for the class attribute.
AttributesOther attributes such as href, id, or type.
ChildrenNested elements or raw HTML strings.
TextEscaped text content.

Example

page := elements.Div(constellation.WebComponent{
    Class: "page-shell",
    Children: []any{
        elements.H1(constellation.WebComponent{
            Text: "Welcome",
        }),
        elements.A(constellation.WebComponent{
            Class:      "text-link",
            Attributes: map[string]string{"href": "/docs"},
            Text:       "Read the docs",
        }),
    },
})

Escaping and children

Text and attribute values are HTML-escaped. Strings placed directly in Children are treated as raw HTML, which is useful for Markdown output but should not contain untrusted input. fmt.Stringer values are escaped.

Void tags such as br, hr, img, input, and meta are rendered without a closing tag. Attributes are sorted by name, so output is stable.

Available helpers

FileHelpers
structure.goDiv, Header, Main, Nav, Section, Footer, ...
headers.goH1 through H6
text.goA, P, Span, Strong, Code, Pre, ...
lists.goUl, Ol, Li, Dl, Dt, Dd
forms.goForm, Input, Label, Button, Select, ...
tables.goTable, Thead, Tbody, Tr, Th, Td, ...
media.goImg, Audio, Video, Iframe, ...
document.goLink, Meta, Script, Style, ...