Label
Label is a form label component with size variants and optional required indicator. Use it for standalone labels or when building custom form layouts.
Import
import { Label } from "@tosui/react";
Basic Usage
- Code
- Preview
<VStack gap={1} align="stretch">
<Label htmlFor="email">Email</Label>
<Input id="email" type="email" placeholder="you@example.com" />
</VStack>
Required Indicator
- Code
- Preview
<VStack gap={1} align="stretch">
<Label htmlFor="username" required>Username</Label>
<Input id="username" placeholder="Enter username" />
</VStack>
Sizes
- Code
- Preview
<VStack gap={4} align="flex-start">
<Label size="xs">Extra small label</Label>
<Label size="sm">Small label (default)</Label>
<Label size="md">Medium label</Label>
<Label size="lg">Large label</Label>
</VStack>
Weights
- Code
- Preview
<VStack gap={4} align="flex-start">
<Label weight="normal">Normal weight</Label>
<Label weight="medium">Medium weight (default)</Label>
<Label weight="semibold">Semibold weight</Label>
<Label weight="bold">Bold weight</Label>
</VStack>
When to Use
- Use Label when you need standalone labels or custom form layouts
- Use FormField when you need labels with helper text, error messages, and automatic accessibility linking
Custom Form Layout
<Box display="grid" gridTemplateColumns="120px 1fr" gap={4} alignItems="center">
<Label htmlFor="first-name">First Name</Label>
<Input id="first-name" placeholder="John" />
<Label htmlFor="last-name">Last Name</Label>
<Input id="last-name" placeholder="Doe" />
<Label htmlFor="email" required>Email</Label>
<Input id="email" type="email" placeholder="you@example.com" />
</Box>
Props Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "xs" | "sm" | "md" | "lg" | "sm" | Label font size |
| weight | "normal" | "medium" | "semibold" | "bold" | "medium" | Label font weight |
| required | boolean | false | Show required asterisk |
| htmlFor | string | - | ID of the associated form control |
| as | ElementType | "label" | HTML element to render |
Label also accepts all Box styling props.
Accessibility
- Renders as a native
<label>element by default - Use
htmlForto associate with the form control'sid - The required asterisk includes
aria-hidden="true"(screen readers announce "required" via the input'saria-required)
TypeScript
import { Label, type LabelProps, type LabelOwnProps } from "@tosui/react";