KodingKaro
HTML · Beginner · HTML Forms

Labels, inputs, and control types

Forms work best when a visitor can identify each field, enter the right kind of value, and submit it predictably.

✓ What you will learn in this topic

  • Explain the purpose of Labels, inputs, and control types in a real HTML document.
  • Choose and apply the elements shown in both examples.
  • Recognize the specific mistake described in this lesson.

Concept explanation

A form groups related controls. Associate a label with a control by matching label for to control id; clicking the label then focuses that control and gives it an accessible name. Input type selects browser behavior such as email, date, checkbox, or password. The name becomes the field key in submitted data. Placeholder is only a hint and should not replace a label.

Syntax

Give controls unique ids, matching label for values, and meaningful name values.

Example 1: a small page

The label is explicitly connected to the input and autocomplete can help fill a known value.

<label for=\"email\">Email address</label>
<input id=\"email\" name=\"email\" type=\"email\" autocomplete=\"email\">

Expected result: A labeled email field appears and the browser can offer email-specific input assistance.

Example 2: a practical page

Each control has a persistent label and name; the input types support email and password entry.

<form action=\"/signup\" method=\"post\">
  <label for=\"name\">Your name</label>
  <input id=\"name\" name=\"name\" autocomplete=\"name\" required>
  <label for=\"email\">Email address</label>
  <input id=\"email\" name=\"email\" type=\"email\" autocomplete=\"email\" required>
  <label for=\"password\">Create password</label>
  <input id=\"password\" name=\"password\" type=\"password\" autocomplete=\"new-password\" required>
  <button type=\"submit\">Register</button>
</form>

Expected result: A visitor can enter a required name, email, and masked password before submitting registration.

Common mistakes

Every control that should be submitted needs a name, and every input needs a programmatically associated label.

Best practices

Use labels, purpose-matching input types, clear names, and server-side validation in addition to browser checks.

Practice exercise

Build a registration form with name, email, password, experience level, and an optional message. Label each control and explain whether GET or POST fits.

Lesson summary

  • Use labels and suitable types, and name controls whose values should be submitted.
  • Use labels, purpose-matching input types, clear names, and server-side validation in addition to browser checks.

Knowledge check

Why is placeholder not an adequate replacement for label?

Show the explanation

A placeholder can disappear as a person types and is not a reliable persistent accessible name.

Practical example

html
<label for=\"email\">Email address</label>
<input id=\"email\" name=\"email\" type=\"email\" autocomplete=\"email\">

Expected result:

A labeled email field appears and the browser can offer email-specific input assistance.

Hands-on practice task

Build a registration form with name, email, password, experience level, and an optional message. Label each control and explain whether GET or POST fits.

In this section

Other lessons in HTML Forms

Broaden your knowledge

Related learning topics