Documentation
¶
Overview ¶
Package label provides constructors and methods for the HTML <label> element.
The <label> HTML element provides a caption for a form control, improving usability and accessibility. Associated with a control via the for attribute or by wrapping the control. Clicking the label focuses or activates the associated control. Essential for accessibility as screen readers announce the label text, and improves user experience by expanding clickable areas for checkboxes and radio buttons.
Index ¶
- Variables
- func For(forID string, str string) *element
- func New(nodes ...node.Node) *element
- func NewLabel(forID string, nodes ...node.Node) *element
- func RawText(str string) *element
- func RawTextf(format string, args ...any) *element
- func Static(str string) *element
- func Text(str string) *element
- func Textf(format string, args ...any) *element
- type Element
Constants ¶
This section is empty.
Variables ¶
var ( TagOpen = []byte("<label") TagClose = []byte("</label>") AttrFor = []byte(" for=\"") )
Byte constants for HTML rendering.
Functions ¶
func For ¶
For creates a label element associated with a form control by ID, with text content. The most common label pattern. Uses text.Text which HTML-escapes the output. Example: label.For("email", "Email Address") Renders: <label for="email">Email Address</label>
func New ¶
New creates a new label element with child nodes. Example: label.New() Renders: <label></label>
func NewLabel ¶
NewLabel creates a new label element with for attribute and child nodes. Example: label.NewLabel("email") Renders: <label for="email"></label>
func RawText ¶
func RawText(str string) *element
RawText creates a new label element with raw text content. Uses text.RawText which is not HTML-escaped. Example: label.RawText("Email <abbr>Addr.</abbr>") Renders: <label>Email <abbr>Addr.</abbr></label>
func RawTextf ¶
RawTextf creates a new label element with formatted raw text content. Uses text.RawTextf which is not HTML-escaped. Example: label.RawTextf("<strong>%s</strong>", field) Renders: <label><strong>Email</strong></label>
func Static ¶
func Static(str string) *element
Static creates a new label element with static text content. Uses text.Static which is not HTML-escaped and is JIT-optimisable. Example: label.Static("Password") Renders: <label>Password</label>