# Label

Renders an accessible label associated with controls.

## Installation

```bash
npx shadcn@latest add https://reactdocs.canceydejean.dev/r/label.json
```

[Registry JSON](https://reactdocs.canceydejean.dev/r/label.json)

## Preview

```tsx
import { Input } from "@/components/ui/input";

import { Label } from "@/components/ui/label/label";

export function Preview() {
  return (
    <div className="grid w-full max-w-xs gap-2">
      <Label htmlFor="preview-email">Email</Label>
      <Input id="preview-email" type="email" placeholder="you@example.com" />
    </div>
  );
}
```


## Source

### label.tsx

```tsx
"use client";

import * as React from "react";

import { cn } from "cn";

/* oxlint-disable jsx-a11y/label-has-associated-control -- Primitive forwards htmlFor/children from callers. */
function Label({ className, ...props }: React.ComponentProps<"label">) {
  return (
    <label
      data-slot="label"
      className={cn(
        "flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
        className,
      )}
      {...props}
    />
  );
}

export { Label };
```



## Usage

Use labels with form controls via `htmlFor` matching the control `id`.

```tsx
import { Input } from "@/components/input/input";
import { Label } from "@/components/label/label";

export function Example() {
  return (
    <div className="grid gap-2">
      <Label htmlFor="email">Email</Label>
      <Input id="email" type="email" placeholder="you@example.com" />
    </div>
  );
}
```

Disabled styling is driven by `group-data-[disabled=true]` on an ancestor, or `peer-disabled` when
the control is a peer sibling.

