label

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	TagOpen  = []byte("<label")
	TagClose = []byte("</label>")

	AttrFor = []byte(" for=\"")
)

Byte constants for HTML rendering.

Functions

func For

func For(forID string, str string) *element

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

func New(nodes ...node.Node) *element

New creates a new label element with child nodes. Example: label.New() Renders: <label></label>

func NewLabel

func NewLabel(forID string, nodes ...node.Node) *element

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

func RawTextf(format string, args ...any) *element

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>

func Text

func Text(str string) *element

Text creates a new label element with text content. Uses text.Text which HTML-escapes the output. Example: label.Text("Email Address") Renders: <label>Email Address</label>

func Textf

func Textf(format string, args ...any) *element

Textf creates a new label element with formatted text content. Uses text.Textf which HTML-escapes the output. Example: label.Textf("Enter %s", field) Renders: <label>Enter Email</label>

Types

type Element

type Element = element

Element is an exported alias for the private element type

Jump to

Keyboard shortcuts

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