Class Label


@Marshalled(typeName="label") public class Label extends HtmlElementMixed<Label>
DTO for an HTML <label> element.

The label element represents a caption for a form control. It provides a programmatic association between the label and the form control, improving accessibility and user experience. When a label is associated with a form control, clicking the label will focus or activate the control.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Label with explicit association Label label1 = label("Username:") .for_("username"); // Label wrapping form control Label label2 = label( input("checkbox").name("agree"), span("I agree to the terms and conditions") ); // Label with form association Label label3 = label("Email Address:") .for_("email") .form("contactForm"); // Label with styling Label label4 = label("Password:") .for_("password") .class_("required");

See Also:
  • Constructor Details

    • Label

      public Label()
      Creates an empty Label element.
    • Label

      public Label(Object... children)
      Creates a Label element with the specified child nodes.
      Parameters:
      children - The child nodes. Must not be null.
  • Method Details

    • for_

      public Label for_(String value)
      for attribute.

      Associates the label with a form control by specifying the control's ID. This creates a programmatic relationship between the label and the form control for accessibility.

      The value should match the ID of a form control element in the same document.

      Parameters:
      value - The ID of the form control to associate with this label. Can be null to unset the attribute.
      Returns:
      This object.
    • form

      public Label form(String value)
      form attribute.

      Associates the label with a form element by specifying the form's ID. This allows the label to be placed outside the form element while still being part of the form.

      The value should match the ID of a form element in the same document.

      Parameters:
      value - The ID of the form element to associate with this label. Can be null to unset the attribute.
      Returns:
      This object.