---
title: Label for Astro
description: "Native Astro labels that name and focus form controls."
seo:
    title: Label for Astro | Shadcn & Tailwind CSS
related:
    - /components/field
    - /components/floating-input
sidebar:
    label: "Label"
---

```astro
---
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
---

<div class="grid w-full max-w-sm gap-2">
  <Label for="email">Email</Label>
  <Input id="email" type="email" placeholder="Enter your email" />
</div>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/label
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/label/index.ts

```ts
export { default as Label } from "./label.astro"
```

#### src/components/ui/label/label.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"label">

const {
  class: className,
  "data-slot": dataSlot = "label",
  ...props
} = Astro.props
---

<label data-slot={dataSlot} class={cn("font-sans text-foreground inline-flex items-center gap-2 text-base/4.5 font-medium sm:text-sm/4", className)} {...props}>
  <slot />
</label>
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import { Label } from "@/components/ui/label"
```

```astro
<Label for="email">Email</Label>
```

## Notes

- Match `for` on `Label` with the target control `id`.
- Use `Label` directly for simple forms and one-off controls.
- When you need descriptions or validation, prefer
  [Field](/components/field) and `FieldLabel`.

## Example

```astro
<Label for="terms">Accept terms and conditions</Label>
```

## API Reference

Read the [installed source](/r/label.json) for the complete prop types.

## When to use Label

Set `for` to the ID of the control being named. Keep the label visible and describe the value the user must provide. Use FieldLabel inside a larger Field composition when that layout is required.

## Keyboard and behavior

A native label can focus its associated input and increase the usable click area. It does not make a missing or duplicate ID valid. Check every label-control pair after rendering repeated fields.

## Theme and layout

Typography follows the shared form style. Required and optional wording should be text, not only a colored mark. Disabled appearance should agree with the associated control.
