Skip to Content
Neshel-UI
Components

Label

A native label with an optional decorative required marker.

Server-compatible (no "use client")

Purpose

Label names a form control. It renders a native <label>.

Import

import.tsx
import { Label } from "@neshel-ui/components";

Usage

Preview: label-field
Preview theme
label-field.tsx
import { Input, Label } from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";

export default function LabelField() {
  return (
    <Stack space="2" className="max-w-sm">
      {/* htmlFor ties the label to the control: clicking it focuses the input. */}
      <Label htmlFor="demo-full-name" required>
        Full name
      </Label>
      <Input id="demo-full-name" name="fullName" autoComplete="name" required />
    </Stack>
  );
}

API

LabelProps

LabelProps
PropTypeDefaultDescription
refRef<HTMLLabelElement>——
requiredboolean—Shows a decorative "*" (hidden from assistive technology; use required on the control).

Also accepts the props of: React DOM attributes.

required adds a decorative * marked aria-hidden; the control's own required attribute is what browsers and screen readers announce.

Accessibility

Connect it with htmlFor (matching the control's id) — this also makes clicking the label focus the control. Selection controls (Select, MultiSelect, Combobox) are labelled the same way through their id.

Common mistakes

  • required on the Label but not on the control: the field is not actually required.
Edit on GitHub

On this page