Label for Astro
Native Astro labels that name and focus form controls.
Installation
bunx --bun shadcn@latest add @gnostic/labelnpx shadcn@latest add @gnostic/labelpnpm dlx shadcn@latest add @gnostic/labelComponent classes: Default Gnostic.
Complete the Installation guide first. Then copy the component files below.
No extra packages are required.
Copy the files
src/components/ui/label/index.ts
export { default as Label } from "./label.astro"
src/components/ui/label/label.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>
Usage
import { Label } from "@/components/ui/label"
<Label for="email">Email</Label>
Notes
- Match
foronLabelwith the target controlid. - Use
Labeldirectly for simple forms and one-off controls. - When you need descriptions or validation, prefer
Field and
FieldLabel.
Example
<Label for="terms">Accept terms and conditions</Label>
API Reference
Read the installed source 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.