Label
A text label for a form control, in the compact text-sm style.
Installation
bash
npx bootcn add labelbash
pnpm dlx bootcn add labelbash
yarn dlx bootcn add labelbash
bunx --bun bootcn add labelThe CLI also installs the design tokens and these components: input. It prints the <link> and <script> tags to add to your layout.
Usage
Always connect the label to its control with for and the control's id. For a label with help text and errors, use the Field component.
Accessibility
- Clicking the label focuses or toggles its control.
- The label is the control's accessible name; do not rely on placeholders.
Dependencies
- Bootstrap 5.3+ CSS.
themes/tokens/tokens.css.- The
inputcomponent.
Source
The exact files the CLI installs (label@1.0.0). View on GitHub · Report an issue
html
<label class="bootcn-label" for="bootcn-label-email">Email address</label>
<input
class="form-control bootcn-input mt-2"
type="email"
id="bootcn-label-email"
name="email"
autocomplete="email"
/>css
.bootcn-label {
display: inline-block;
font-size: 0.875rem;
font-weight: 500;
line-height: 1;
user-select: none;
}
/* Dim the label of a disabled control that follows it. */
.bootcn-label:has(+ :disabled),
.bootcn-label:has(+ * :disabled) {
cursor: not-allowed;
opacity: 0.5;
}
