Label
A label names a form control, and clicking it moves focus to that control.
When to use
Section titled “When to use”- Give every input, select and checkbox a visible label.
- Put labels above inputs and selects, and beside checkboxes.
- Keep labels short; put guidance in a hint below the field.
Anatomy
Section titled “Anatomy”- 1Label text
- 2Required mark
- 3The control it names
One line of text-sm medium text in foreground. A disabled control dims its label too.
Variants
Section titled “Variants”There is one style.
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
htmlFor |
for |
label on the field |
string | none | The id of the control it names. |
import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"
export default function LabelDemo() { return ( <div className="grid w-full max-w-sm gap-2"> <Label htmlFor="label-demo-name">Nama lengkap</Label> <Input id="label-demo-name" /> </div> )}<script setup lang="ts">import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"</script>
<template> <div class="grid w-full max-w-sm gap-2"> <Label for="label-demo-name-vue">Nama lengkap</Label> <Input id="label-demo-name-vue" /> </div></template>// Flutter has no separate label widget: form fields take a `label`.import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class LabelDemo extends StatelessWidget { const LabelDemo({super.key});
@override Widget build(BuildContext context) { return ConstrainedBox( constraints: const BoxConstraints(maxWidth: 384), child: ShadInputFormField( id: 'name', label: const Text('Nama lengkap'), ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/label.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/label.jsonAccessibility
Section titled “Accessibility”- Renders a native
label, so clicking it focuses the control. - Flutter has no separate label widget; pass
labelto the form field.
