OnlineCBT Logo OnlineCBT
HTML Tutorial
HTML · LESSON 31

Labels, Placeholders and Required Fields

By Ratan Updated: 16 Oct 2026

Improve form usability and accessibility using <label>, placeholder, and required attributes.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. The Element & Accessibility

Every form input must be paired with a . To bind a label to an input, match the label's for attribute with the input's id attribute:



  • Clicking the label automatically focuses the associated text input or toggles the checkbox.
  • Screen readers announce the label text when the student tabs through inputs.

2. placeholder vs label

A placeholder provides a short hint of the expected format (e.g., placeholder="DD/MM/YYYY"). Never use placeholders as substitutes for labels, because placeholders disappear as soon as the user starts typing.

3. Enforcing Inputs with required

Adding the boolean required attribute prevents form submission if the field is left blank, displaying a native browser validation tooltip.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat