Label provides a text caption for form controls and connects to inputs using htmlFor.
Clicking the label focuses the associated input. Screen readers read the label when the input is focused.
<Label htmlFor='basic-input'>Username</Label>
<input id='basic-input' type='text' />Label with required prop. Exposes data-required for styling hooks. The control itself should also have required or aria-required.
<Label htmlFor='required-input' required>Email *</Label>
<input id='required-input' type='email' required />Label with optional prop for visual indicator. Exposes data-optional.
<Label htmlFor='optional-input' optional>Phone</Label>
<input id='optional-input' type='tel' />Label with disabled prop. Exposes data-disabled. The associated control should also be disabled.
<Label htmlFor='disabled-input' disabled>Organization</Label>
<input id='disabled-input' disabled value='Acme Corp' />Label with readOnly prop. Exposes data-readonly.
<Label htmlFor='readonly-input' readOnly>Account ID</Label>
<input id='readonly-input' readOnly value='ACC-12345' />Label with invalid prop. Exposes data-invalid. The control should have aria-invalid="true".
<Label htmlFor='invalid-input' invalid>Password</Label>
<input id='invalid-input' aria-invalid='true' aria-describedby='invalid-error' />
<div id='invalid-error' role='alert'>Password must be at least 8 characters</div>Label can render as different HTML elements using the as prop.
<Label as='span' htmlFor='label-span'>As span</Label>
<input id='label-span' type='text' />
<Label as='div' htmlFor='label-div'>As div</Label>
<input id='label-div' type='text' />