A <label> gives a form control an accessible name and a larger click target. There are two ways to associate them, and doing so is essential for accessibility.
Metode 1: for + id (eksplisit)
Email address
A <label> gives a form control an accessible name and a larger click target. There are two ways to associate them, and doing so is essential for accessibility.
for + id (eksplisit)Email address
Label for cocog karo input id. Iki bisa dadi minangka urutaning markup apa wae.
<label>
Email address
<input type="email" />
</label>
Input ana ing jero label — ora perlu id.
<label><input type="checkbox" /> I agree to the terms</label>
<!-- clicking the text toggles the checkbox -->
<input placeholder="Email" /> <!-- ❌ disappears on typing, poor contrast, not a label -->
A placeholder ilang nalika user ngetik lan ora diumum kanthi andal — aja bisaa digunakake minangka label.
<input type="search" aria-label="Search products" /> <!-- accessible name, no visible label -->
Gunakake aria-label (utawa aria-labelledby) mung nalika label sing katon ora kasil.
Label sing asosiasi kanthi bener minangka salah sawijining praktik aksesibilitas sing paling nyata kanggo formulir — menehi saben kontrol jeneng kanggo teknologi pendamping lan nambahi target klik kanggo kabeh.
Nambakake label <label> nyata; mundur menyang aria-label mung nalika dibutuhake, lan aja pernah ngandelake placeholder minangka label.