Performance: Labels and placeholders
This concept affects page accessibility and user interaction responsiveness, indirectly influencing user experience and input delay.
<label for="name">Name</label> <input id="name" type="text" placeholder="Enter your name">
<input type="text" placeholder="Enter your name">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Input with placeholder only | Minimal DOM nodes | 0 reflows | Low paint cost | [!] OK but poor accessibility |
| Input with label and placeholder | One extra DOM node (label) | 0 reflows | Slightly higher paint cost | [OK] Good for accessibility and INP |
<label> element in an HTML form?for attribute?for="email" in label and id="email" in input, which is correct.<label for="username">Username</label> <input id="username" type="text" placeholder="Enter your username">
<label for="phone">Phone Number</label> <input placeholder="Enter phone number">
for attribute value "phone" does not match any id on the input (input has no id).text.for="email" in label and matching id="email" in input links them for accessibility.type="email" helps browsers validate and show correct keyboard on mobile.Pass the test and this pattern moves unknown