Skip to main content

Label

Accessible label for form controls.

Usage

<w-label for="my-input">
<label>Email address</label>
</w-label>
<input id="my-input" type="email" />

Props

PropTypeDefaultDescription
forstring""ID of the labeled control
requiredbooleanfalseShow required indicator
disabledbooleanfalseStyle as disabled

Slots

SlotElementDescription
(default)LabelLabel text content

Examples

With Custom Component

<w-label for="my-spinbutton">
<label>Quantity</label>
</w-label>
<w-spinbutton id="my-spinbutton" label="Quantity">
...
</w-spinbutton>

Required Field

<w-label for="name" required>
<label>Name</label>
</w-label>
<input id="name" required />

Styling

w-label {
display: block;
cursor: pointer;
}

w-label[required]::after {
content: " *";
color: red;
}

w-label[disabled] {
opacity: 0.5;
cursor: not-allowed;
}

Accessibility

  • Clicking label focuses the associated control
  • Works with both native inputs and custom components
  • Properly associates via for attribute