Skip to content

Label ​

A text label for a form control, in the compact text-sm style.

Installation ​

bash
npx bootcn add label
bash
pnpm dlx bootcn add label
bash
yarn dlx bootcn add label
bash
bunx --bun bootcn add label

The 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 input component.

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;
}

Released under the MIT License. Not affiliated with Bootstrap or shadcn/ui.