html

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package html provides semantic, ADA-compliant HTML element primitives for the GoFastr core-ui framework.

The package maps 1:1 to HTML tags: every exported function produces a single element (Div, Button, Heading, Form, Table…). Higher-level patterns that compose multiple elements (accordion, pagination, tabs, breadcrumbs, etc.) live in core-ui/patterns; opinionated semantic components live in framework/ui.

Every function returns a render.HTML value and uses the core render package's Tag and VoidTag builders to produce well-formed markup. ARIA landmarks and roles are applied automatically where appropriate.

Usage

Elements accept an Attrs map (which may be nil) and variadic children:

heading := html.Heading(2, html.Attrs{"class": "title"},
    render.Text("Welcome"))
// <h2 class="title" id="heading-welcome">Welcome</h2>

Index

Constants

View Source
const (
	RoleBanner        = "banner"
	RoleNavigation    = "navigation"
	RoleMain          = "main"
	RoleContentinfo   = "contentinfo"
	RoleComplementary = "complementary"
	RoleSearch        = "search"
	RoleForm          = "form"
	RoleRegion        = "region"
)

Landmark roles.

View Source
const (
	RoleDialog      = "dialog"
	RoleAlert       = "alert"
	RoleAlertDialog = "alertdialog"
	RoleStatus      = "status"
	RoleLog         = "log"
	RoleMarquee     = "marquee"
	RoleTimer       = "timer"
)

Live region roles.

View Source
const (
	RoleButton   = "button"
	RoleLink     = "link"
	RoleCheckbox = "checkbox"
	RoleRadio    = "radio"
	RoleTab      = "tab"
	RoleTabList  = "tablist"
	RoleTabPanel = "tabpanel"
)

Widget roles.

View Source
const (
	RoleGrid     = "grid"
	RoleGridCell = "gridcell"
	RoleRow      = "row"
	RoleRowGroup = "rowgroup"
	RoleTable    = "table"
)

Grid and table roles.

View Source
const (
	RoleList     = "list"
	RoleListItem = "listitem"
	RoleListbox  = "listbox"
	RoleOption   = "option"
	RoleMenu     = "menu"
	RoleMenuItem = "menuitem"
)

List and menu roles.

Variables

This section is empty.

Functions

func Abbr

func Abbr(cfg AbbrConfig, children ...render.HTML) render.HTML

Abbr produces an <abbr> element with a title attribute for the full expansion of the abbreviation. Required: Title.

func Article

func Article(cfg ArticleConfig, children ...render.HTML) render.HTML

Article produces an <article> element representing a self-contained composition in a page.

func Aside

func Aside(cfg AsideConfig, children ...render.HTML) render.HTML

Aside produces an <aside> element with role="complementary". Required: Label or LabelledBy.

func Audio

func Audio(cfg AudioConfig, children ...render.HTML) render.HTML

Audio produces an <audio> element for sound content.

func BR

func BR() render.HTML

BR produces a void <br> element (line break).

func Blockquote

func Blockquote(cfg TextConfig, children ...render.HTML) render.HTML

Blockquote produces a <blockquote> element.

func Button

func Button(cfg ButtonConfig) render.HTML

Button produces a <button> element. Required: Label (used as both visible text and aria-label).

func ButtonGroup

func ButtonGroup(cfg ButtonGroupConfig, children ...render.HTML) render.HTML

ButtonGroup produces a <div> with role="group" containing buttons.

func Caption

func Caption(cfg CaptionConfig, children ...render.HTML) render.HTML

Caption produces a <caption> element for a table description.

func Checkbox

func Checkbox(cfg CheckboxConfig) render.HTML

Checkbox produces an <input type="checkbox"> element. Required: Name.

func Cite

func Cite(cfg TextConfig, children ...render.HTML) render.HTML

Cite produces a <cite> element for the title of a work.

func Code

func Code(cfg TextConfig, children ...render.HTML) render.HTML

Code produces a <code> element for inline code fragments.

func DescriptionDetail

func DescriptionDetail(cfg TextConfig, children ...render.HTML) render.HTML

DescriptionDetail produces a <dd> element for a description in a description list.

func DescriptionList

func DescriptionList(cfg TextConfig, children ...render.HTML) render.HTML

DescriptionList produces a <dl> element for name-value groups.

func DescriptionTerm

func DescriptionTerm(cfg TextConfig, children ...render.HTML) render.HTML

DescriptionTerm produces a <dt> element for a term in a description list.

func Details

func Details(cfg DetailsConfig, children ...render.HTML) render.HTML

Details produces a <details> element for a disclosure widget.

func Div

func Div(cfg DivConfig, children ...render.HTML) render.HTML

Div produces a <div> element.

func Em

func Em(cfg TextConfig, children ...render.HTML) render.HTML

Em produces an <em> element for stress emphasis.

func FieldSet

func FieldSet(cfg FieldSetConfig, children ...render.HTML) render.HTML

FieldSet produces a <fieldset> element with a <legend> derived from cfg.Legend. Required: Legend.

func FigCaption

func FigCaption(cfg FigCaptionConfig, children ...render.HTML) render.HTML

FigCaption produces a <figcaption> element for a figure caption.

func Figure

func Figure(cfg FigureConfig, children ...render.HTML) render.HTML

Figure produces a <figure> element for self-contained content referenced from the main flow.

func Footer(cfg FooterConfig, children ...render.HTML) render.HTML

Footer produces a <footer> element. When cfg.ContentInfo is true it also carries role="contentinfo" (use this for the page-wide footer only; nested article/section footers should leave it false).

func Form

func Form(cfg FormConfig, children ...render.HTML) render.HTML

Form produces a <form> element. Required: Method.

func Group

func Group(cfg GroupConfig, children ...render.HTML) render.HTML

Group produces a <div> element with the given ARIA role. Required: Role.

func HR

func HR(cfg TextConfig) render.HTML

HR produces a void <hr> element (thematic break).

func Header(cfg HeaderConfig, children ...render.HTML) render.HTML

Header produces a <header> element. When cfg.Banner is true it also carries role="banner" (use this for the page-wide banner only; nested page-content headers should leave Banner=false).

func Heading

func Heading(cfg HeadingConfig, children ...render.HTML) render.HTML

Heading produces an <h1> through <h6> element. Required: Level (1-6). Auto-generates an id attribute from the text content of children for aria-labelledby references. If cfg.ID is set, it is used instead.

func Image

func Image(cfg ImageConfig) render.HTML

Image produces a void <img> element. Required: Src and Alt. Empty Alt marks the image as decorative (role="presentation" is added automatically).

func Input

func Input(cfg InputConfig) render.HTML

Input produces a void <input> element. Required: Type and Name.

func Kbd

func Kbd(cfg TextConfig, children ...render.HTML) render.HTML

Kbd produces a <kbd> element for keyboard input — a single key, a chord, or a sequence. Pairs with framework/ui.ShortcutHint for rendering shortcut chips. Pure semantic markup, no scripting.

func Label

func Label(cfg LabelConfig) render.HTML

Label produces a <label> element with a for attribute linking it to the form control with the given ID. Required: For and Text.

func Legend

func Legend(cfg TextConfig, children ...render.HTML) render.HTML

Legend produces a <legend> element.

func Link(cfg LinkConfig) render.HTML

Link produces an <a> element with the given href and text content. Required: Href and Text.

func LinkHTML

func LinkHTML(cfg LinkHTMLConfig) render.HTML

LinkHTML produces an <a> element with raw HTML content (not escaped). Required: Href and Content.

func ListItem

func ListItem(cfg ListItemConfig, children ...render.HTML) render.HTML

ListItem produces an <li> element with role="listitem".

func Main

func Main(cfg MainConfig, children ...render.HTML) render.HTML

Main produces a <main> element with role="main" and id="main-content" for skip-navigation links. If cfg.ID is set, it overrides the default id.

func Mark

func Mark(cfg TextConfig, children ...render.HTML) render.HTML

Mark produces a <mark> element for highlighted text.

func Meta

func Meta(name, content string) render.HTML

Meta produces a void <meta> element with name and content attributes.

func Nav(cfg NavConfig, children ...render.HTML) render.HTML

Nav produces a <nav> element with role="navigation". Required: Label or LabelledBy.

func Option

func Option(value, text string, selected bool) render.HTML

Option produces an <option> element with value and selected state.

func OrderedList

func OrderedList(cfg ListConfig, children ...render.HTML) render.HTML

OrderedList produces an <ol> element with role="list".

func Paragraph

func Paragraph(cfg TextConfig, children ...render.HTML) render.HTML

Paragraph produces a <p> element.

func Pre

func Pre(cfg TextConfig, children ...render.HTML) render.HTML

Pre produces a <pre> element for preformatted text.

func Radio

func Radio(cfg RadioConfig) render.HTML

Radio produces an <input type="radio"> element. Required: Name and Value.

func Script

func Script(src string) render.HTML

Script produces a <script> element with the given src.

func Section

func Section(cfg SectionConfig, children ...render.HTML) render.HTML

Section produces a <section> element. Required: Label or LabelledBy. Automatically adds role="region" and the corresponding aria attribute.

func Select

func Select(cfg SelectConfig) render.HTML

Select produces a <select> element containing the given options. Required: Name.

func Small

func Small(cfg TextConfig, children ...render.HTML) render.HTML

Small produces a <small> element for side comments.

func Source

func Source(cfg SourceConfig) render.HTML

Source produces a void <source> element for use inside <audio> or <video>. Required: Src and Type.

func Span

func Span(cfg TextConfig, children ...render.HTML) render.HTML

Span produces a <span> element.

func Strong

func Strong(cfg TextConfig, children ...render.HTML) render.HTML

Strong produces a <strong> element for strong importance.

func StyleSheet

func StyleSheet(href string) render.HTML

StyleSheet produces a <link> element with rel="stylesheet".

func Summary

func Summary(cfg SummaryConfig, children ...render.HTML) render.HTML

Summary produces a <summary> element for the summary/caption of a details element.

func TD

func TD(cfg TDConfig, children ...render.HTML) render.HTML

TD produces a <td> element with role="cell".

func TH

func TH(cfg THConfig, children ...render.HTML) render.HTML

TH produces a <th> element. The scope attribute defaults to "col" (columnheader) unless cfg.Scope is set. The role is set to "columnheader" for scope="col" and "rowheader" for scope="row".

func Table

func Table(cfg TableConfig, children ...render.HTML) render.HTML

Table produces a <table> element with role="table".

func TableRow

func TableRow(cfg TableRowConfig, children ...render.HTML) render.HTML

TableRow produces a <tr> element with role="row".

func Tbody

func Tbody(cfg TableSectionConfig, children ...render.HTML) render.HTML

Tbody produces a <tbody> element with role="rowgroup".

func TextArea

func TextArea(cfg TextAreaConfig) render.HTML

TextArea produces a <textarea> element. Required: Name. Content is HTML-escaped on render; for unescaped content (rare) drop to render.Tag("textarea", ...) directly.

func Tfoot

func Tfoot(cfg TableSectionConfig, children ...render.HTML) render.HTML

Tfoot produces a <tfoot> element with role="rowgroup".

func Thead

func Thead(cfg TableSectionConfig, children ...render.HTML) render.HTML

Thead produces a <thead> element with role="rowgroup".

func Time

func Time(cfg TimeConfig, children ...render.HTML) render.HTML

Time produces a <time> element with a machine-readable datetime attribute. Required: Datetime.

func UnorderedList

func UnorderedList(cfg ListConfig, children ...render.HTML) render.HTML

UnorderedList produces a <ul> element with role="list".

func Video

func Video(cfg VideoConfig, children ...render.HTML) render.HTML

Video produces a <video> element for video content.

Types

type AbbrConfig

type AbbrConfig struct {
	Title      string // required: full expansion
	Class      string
	ID         string
	ExtraAttrs Attrs
}

AbbrConfig configures an <abbr> element. Required: Title.

type ArticleConfig

type ArticleConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

ArticleConfig configures an <article> element. No required fields.

type AsideConfig

type AsideConfig struct {
	Label      string // required → aria-label
	LabelledBy string // alternative → aria-labelledby
	Class      string
	ID         string
	ExtraAttrs Attrs
}

AsideConfig configures an <aside> element. Required: Label or LabelledBy (one must be set). Automatically adds role="complementary".

type Attrs

type Attrs = map[string]string

Attrs is a type alias for map[string]string, matching render.Attrs.

func Aria

func Aria(key, value string) Attrs

Aria returns an Attrs containing a single aria-* attribute. The key should not include the "aria-" prefix; it is added automatically.

func Bind

func Bind(key string) Attrs

Bind returns Attrs that create a two-way binding between an input element and a named state key. The runtime.js listens for input events on elements with data-bind and dispatches actions with the new value.

Usage:

search := signal.New("")
html.Input(html.Text, "search",
    html.Bind("search"),
    html.Placeholder("Search..."),
)

func Classes

func Classes(classes map[string]bool) Attrs

Classes converts a map of class names to booleans into an Attrs containing a single "class" attribute. Only classes with a true value are included.

func ContainerType

func ContainerType(containerType string, name string) Attrs

ContainerType returns Attrs that declare an element as a CSS container query context. The containerType is typically "inline-size" (respond to width) or "size" (width + height). Use this on parent elements whose children should respond to the parent's size.

html.Div(
	html.ContainerType("inline-size", "product-grid"),
	productCards...,
)

func DataAttrs

func DataAttrs(data map[string]string) Attrs

DataAttrs converts a map of key-value pairs into data-* attributes. Keys should not include the "data-" prefix; it is added automatically.

func ID

func ID(id string) Attrs

ID returns an Attrs containing only the given id attribute.

func MergeAttrs

func MergeAttrs(attrsList ...Attrs) Attrs

MergeAttrs merges zero or more attribute maps. Later maps overwrite earlier ones for the same key. Returns nil if no maps are provided.

func OnChange

func OnChange(action string) Attrs

OnChange returns Attrs with data-action set and data-action-type="change". Used on select/input elements for change handling.

func OnClick

func OnClick(action string) Attrs

OnClick returns Attrs with data-action set to the given action name. Used to wire up click handlers on html. Example: Button("Save", OnClick("save"))

func OnInput

func OnInput(action string) Attrs

OnInput returns Attrs with data-action set and data-action-type="input". Used on input/textarea elements for real-time input handling.

func OnSubmit

func OnSubmit(action string) Attrs

OnSubmit returns Attrs with data-action set and data-action-type="submit". Used on form html.

type AudioConfig

type AudioConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

AudioConfig configures an <audio> element. No required fields.

type ButtonConfig

type ButtonConfig struct {
	Label      string // required → text content AND aria-label
	Type       string // defaults to "button"
	Class      string
	ID         string
	ExtraAttrs Attrs
}

ButtonConfig configures a <button> element. Required: Label (used as both visible text and aria-label).

type ButtonGroupConfig

type ButtonGroupConfig struct {
	AriaLabel  string
	Class      string
	ID         string
	ExtraAttrs Attrs
}

ButtonGroupConfig configures a <div> with role="group" containing buttons. No required fields.

type CaptionConfig

type CaptionConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

CaptionConfig configures a <caption> element. No required fields.

type CheckboxConfig

type CheckboxConfig struct {
	Name       string // required
	Value      string // optional
	ID         string // optional (but strongly recommended for label association)
	Checked    bool   // optional
	Class      string
	ExtraAttrs Attrs
}

CheckboxConfig configures a void <input type="checkbox"> element. Required: Name.

type DetailsConfig

type DetailsConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
	// Disclosure marks this details element as a dismissible disclosure
	// (mobile hamburger nav, popover, etc.). The runtime will close it
	// automatically on SPA navigation and on Escape. See ARCHITECTURE.md
	// data-fui-disclosure.
	Disclosure bool
	// Open opens the details element on initial render.
	Open bool
}

DetailsConfig configures a <details> element. No required fields.

type DivConfig

type DivConfig struct {
	Class      string
	ID         string
	Role       string
	AriaLabel  string
	ExtraAttrs Attrs // passthrough for any extra attributes
}

DivConfig configures a <div> element. No required fields.

type FieldSetConfig

type FieldSetConfig struct {
	Legend     string // required: becomes <legend> text
	Class      string
	ID         string
	ExtraAttrs Attrs
}

FieldSetConfig configures a <fieldset> element. Required: Legend.

type FigCaptionConfig

type FigCaptionConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

FigCaptionConfig configures a <figcaption> element. No required fields.

type FigureConfig

type FigureConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

FigureConfig configures a <figure> element. No required fields.

type FooterConfig

type FooterConfig struct {
	Class       string
	ID          string
	ExtraAttrs  Attrs
	ContentInfo bool // explicit opt-in for role="contentinfo"
}

FooterConfig configures a <footer> element. Set ContentInfo=true to mark it as the page-wide footer (adds role="contentinfo"). Defaults to false because a page may have multiple <footer> elements (article footers, section footers) and only ONE should carry the contentinfo role.

type FormConfig

type FormConfig struct {
	Method     string // required: "GET" or "POST"
	Action     string // optional: form action URL
	Class      string
	ID         string
	ExtraAttrs Attrs
}

FormConfig configures a <form> element. Required: Method.

type GroupConfig

type GroupConfig struct {
	Role       string // required
	AriaLabel  string
	Class      string
	ID         string
	ExtraAttrs Attrs
}

GroupConfig configures a <div> with an ARIA role. Required: Role.

type HeaderConfig

type HeaderConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
	Banner     bool // explicit opt-in for role="banner"
}

HeaderConfig configures a <header> element. Set Banner=true to mark it as the page-wide banner (adds role="banner"). Defaults to false because a page may have multiple <header> elements (article headers, section headers, page-content headers) and only ONE should carry the banner role.

type HeadingConfig

type HeadingConfig struct {
	Level      int // required: 1-6
	Class      string
	ID         string
	ExtraAttrs Attrs
}

HeadingConfig configures an <h1>–<h6> element. Required: Level (1-6).

type ImageConfig

type ImageConfig struct {
	Src        string // required
	Alt        string // required (empty = decorative image)
	Class      string
	ID         string
	ExtraAttrs Attrs
}

ImageConfig configures a void <img> element. Required: Src and Alt (empty Alt = decorative, gets role="presentation").

type InputConfig

type InputConfig struct {
	Type        string // required: "text", "email", "password", etc.
	Name        string // required: form field name
	Value       string // optional: initial value (typed equivalent of Attrs{"value": ...})
	Placeholder string // optional: placeholder text
	Class       string
	ID          string
	ExtraAttrs  Attrs // escape hatch for attributes not covered by typed fields
}

InputConfig configures a void <input> element. Required: Type and Name.

type LabelConfig

type LabelConfig struct {
	For        string // required: ID of the associated form control
	Text       string // required: label text
	Class      string
	ID         string
	ExtraAttrs Attrs
}

LabelConfig configures a <label> element. Required: For (the ID of the form control) and Text.

type LinkConfig

type LinkConfig struct {
	Href       string // required
	Text       string // required (visible text content)
	Class      string
	ID         string
	ExtraAttrs Attrs
}

LinkConfig configures an <a> element. Required: Href and Text.

type LinkHTMLConfig

type LinkHTMLConfig struct {
	Href       string      // required
	Content    render.HTML // required (raw HTML content)
	Class      string
	ID         string
	ExtraAttrs Attrs
}

LinkHTMLConfig configures an <a> element with raw HTML content. Required: Href and Content.

type ListConfig

type ListConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

ListConfig configures a list element (<ul> or <ol>). No required fields.

type ListItemConfig

type ListItemConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

ListItemConfig configures an <li> element. No required fields.

type MainConfig

type MainConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

MainConfig configures a <main> element. Automatically adds role="main" and id="main-content".

type NavConfig struct {
	Label      string // required → aria-label
	LabelledBy string // alternative → aria-labelledby
	Class      string
	ID         string
	ExtraAttrs Attrs
}

NavConfig configures a <nav> element. Required: Label or LabelledBy (one must be set — becomes aria-label/aria-labelledby). Automatically adds role="navigation".

type RadioConfig

type RadioConfig struct {
	Name       string // required
	Value      string // required
	ID         string // optional (but strongly recommended)
	Checked    bool   // optional
	Class      string
	ExtraAttrs Attrs
}

RadioConfig configures a void <input type="radio"> element. Required: Name and Value.

type SectionConfig

type SectionConfig struct {
	Label      string // required → aria-label
	LabelledBy string // alternative → aria-labelledby
	Class      string
	ID         string
	ExtraAttrs Attrs
}

SectionConfig configures a <section> element. Required: Label or LabelledBy (one must be set — becomes aria-label/aria-labelledby).

type SelectConfig

type SelectConfig struct {
	Name       string         // required: form field name
	Options    []SelectOption // required: at least one option
	Class      string
	ID         string
	ExtraAttrs Attrs
}

SelectConfig configures a <select> element. Required: Name and Options.

type SelectOption

type SelectOption struct {
	Value    string
	Text     string
	Selected bool
}

SelectOption represents a single <option> within a <select> element.

type SourceConfig

type SourceConfig struct {
	Src        string // required
	Type       string // required: MIME type
	Class      string
	ID         string
	ExtraAttrs Attrs
}

SourceConfig configures a void <source> element. Required: Src and Type.

type SummaryConfig

type SummaryConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

SummaryConfig configures a <summary> element. No required fields.

type TDConfig

type TDConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

TDConfig configures a <td> element.

type THConfig

type THConfig struct {
	Scope      string // defaults to "col"
	Class      string
	ID         string
	ExtraAttrs Attrs
}

THConfig configures a <th> element. Scope defaults to "col" (columnheader).

type TableConfig

type TableConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

TableConfig configures a <table> element. Automatically adds role="table".

type TableRowConfig

type TableRowConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

TableRowConfig configures a <tr> element.

type TableSectionConfig

type TableSectionConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

TableSectionConfig configures thead/tbody/tfoot elements.

type TextAreaConfig

type TextAreaConfig struct {
	Name        string // required: form field name
	Content     string // optional: initial text content (HTML-escaped on render)
	Placeholder string // optional: placeholder text
	Rows        int    // optional: rows attribute (>0 only)
	Cols        int    // optional: cols attribute (>0 only)
	Class       string
	ID          string
	ExtraAttrs  Attrs // escape hatch for attributes not covered by typed fields
}

TextAreaConfig configures a <textarea> element. Required: Name.

type TextConfig

type TextConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

TextConfig configures a text container element (Paragraph, Span, Strong, Em, etc.). No required fields — used for generic text containers.

type TimeConfig

type TimeConfig struct {
	Datetime   string // required: machine-readable datetime
	Class      string
	ID         string
	ExtraAttrs Attrs
}

TimeConfig configures a <time> element. Required: Datetime.

type VideoConfig

type VideoConfig struct {
	Class      string
	ID         string
	ExtraAttrs Attrs
}

VideoConfig configures a <video> element. No required fields.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL