Skip to content

Label

Renders an accessible label associated with form controls.

Installation

bash
npx @galaxy-stack/nebula-cli@latest add label
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add label
bash
yarn dlx @galaxy-stack/nebula-cli@latest add label
bash
bunx @galaxy-stack/nebula-cli@latest add label
bash
# If you have installed galaxy-design globally
galaxy-design add label

API Reference

Props

PropTypeDefaultDescriptionFrameworks
htmlForstring-ID of the element the label is associated withReact, React Native
forstring-ID of the element the label is associated withVue, Angular, Flutter
classNamestring''CSS class names for the labelReact, React Native
classstring''CSS class names for the labelVue, Angular, Flutter
childrenReactNode-Label contentReact, React Native
textstring-Label text contentFlutter

Usage

Basic Form

vue
<template>
  <div class="space-y-4">
    <div class="space-y-2">
      <Label for="username">Username</Label>
      <Input id="username" placeholder="johndoe" />
    </div>
    <div class="space-y-2">
      <Label for="password">Password</Label>
      <Input id="password" type="password" />
    </div>
  </div>
</template>
tsx
<div className="space-y-4">
  <div className="space-y-2">
    <Label htmlFor="username">Username</Label>
    <Input id="username" placeholder="johndoe" />
  </div>
  <div className="space-y-2">
    <Label htmlFor="password">Password</Label>
    <Input id="password" type="password" />
  </div>
</div>
html
<div class="space-y-4">
  <div class="space-y-2">
    <ui-label for="username">Username</ui-label>
    <ui-input id="username" placeholder="johndoe" />
  </div>
  <div class="space-y-2">
    <ui-label for="password">Password</ui-label>
    <ui-input id="password" type="password" />
  </div>
</div>

With Required Indicator

vue
<template>
  <div class="space-y-2">
    <Label for="required-field">
      Name
      <span class="text-destructive">*</span>
    </Label>
    <Input id="required-field" required />
  </div>
</template>
tsx
<div className="space-y-2">
  <Label htmlFor="required-field">
    Name
    <span className="text-destructive">*</span>
  </Label>
  <Input id="required-field" required />
</div>
html
<div class="space-y-2">
  <ui-label for="required-field">
    Name
    <span class="text-destructive">*</span>
  </ui-label>
  <ui-input id="required-field" required />
</div>

With Checkbox

vue
<template>
  <div class="flex items-center space-x-2">
    <Checkbox id="terms" />
    <Label
      for="terms"
      class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
    >
      Accept terms and conditions
    </Label>
  </div>
</template>
tsx
<div className="flex items-center space-x-2">
  <Checkbox id="terms" />
  <Label
    htmlFor="terms"
    className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
  >
    Accept terms and conditions
  </Label>
</div>
html
<div class="flex items-center space-x-2">
  <ui-checkbox id="terms" />
  <ui-label
    for="terms"
    class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
  >
    Accept terms and conditions
  </ui-label>
</div>

API Reference

Props

PropTypeDefaultDescription
for / htmlForstring-The id of the form control to associate with
class / classNamestring-Additional CSS classes

Framework-Specific

Vue

  • Uses Radix Vue Label component
  • Props: for, asChild

React

  • Uses Radix UI Label component
  • Props: htmlFor, asChild

Angular

  • Custom implementation with HostBinding
  • Props: for, class

Accessibility

  • Properly associates label with form control using for attribute
  • Supports click to focus associated input
  • Works with screen readers
  • Supports disabled state styling (peer-disabled)

Styling

The Label component uses these base styles:

css
text-sm font-medium leading-none
peer-disabled:cursor-not-allowed
peer-disabled:opacity-70

You can override or extend these styles by passing custom classes.

Author

Bùi Trọng Hiếu (kevinbui)

License

MIT © 2025 Bùi Trọng Hiếu (kevinbui)

Released under the MIT License.