CodeBlanks Logo Icon CodeBlanks

Person fields

HTML course · Intermediate · Lesson 43/67

Add name, email and phone fields with correct types.

The text, email and tel types

A contact form has three core person fields: name, email and phone. <input type='text'> takes free text, <input type='email'> validates the email shape, <input type='tel'> opens the right on-screen keyboard for phone numbers.

Pick the right type and the browser does built-in validation, shows the right mobile keyboard and builds user trust in the form. Pick the wrong one and you lose all of that.

required and placeholder

The required attribute marks a field that can't be left empty; the browser stops the submit and warns the user. The placeholder attribute shows a short hint about what to type.

Placeholder is not a default value: it's greyed out until the user types and it's never submitted to the server. Don't use it instead of a label; always name the field with a label.

Exercise Add the email and phone fields

Add two more label+input pairs to the 'Contact details' fieldset. First: label for='email' 'Email', input type='email' id='email' name='email' placeholder='name.surname@example.com' required. Second: label for='phone' 'Phone', input type='tel' id='phone' name='phone' placeholder='+1 555 123 4567'.

Show example solution
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Cafe Dem - Contact</title>
  </head>
  <body>
    <form action="/contact" method="post">
      <fieldset>
        <legend>Contact details</legend>
        <label for="name">Your name</label>
        <input type="text" id="name" name="name">
        <label for="email">Email</label>
        <input type="email" id="email" name="email" placeholder="name.surname@example.com" required>
        <label for="phone">Phone</label>
        <input type="tel" id="phone" name="phone" placeholder="+1 555 123 4567">
      </fieldset>
    </form>
  </body>
</html>

Test yourself

  1. Which input type validates the email format automatically?

    <input type="?" name="email">
    • text
    • email
    • tel
    • search
    Show answer

    email — Correct! type='email' tells the browser to validate the email shape.

  2. Fill in: add required

    <input type="email" id="email" name="email" placeholder="name.surname@example.com" ____>
    Show answer
    <input type="email" id="email" name="email" placeholder="name.surname@example.com" required>
  3. Match types to their expected input

    text
    Full name
    email
    Email address
    tel
    Phone number
    password
    Secret password

All lessons in Intermediate