Lesson 7 of 8

The right type for each field

Goal

Bring up the right keyboard

01

Explanation

On a phone, a field's attributes decide which keyboard the user gets and what autofill suggests, and a well-configured field saves them half the typing.

type="tel" opens the phone keypad, and type="email" opens a keyboard with @ on it and checks the email format without any code from you. autocomplete tells the browser what kind of data the field holds, such as tel and email, or one-time-code, which makes the phone suggest the verification code from a text message right away.

A common mistake is using type="number" for a code or a phone number. A number you never add or subtract isn't a good fit for number: it adds up and down arrows, ignores maxlength, and the mouse wheel can change its value. The alternative is inputmode="numeric", but it only changes the keyboard and validates nothing, so pair it with a pattern.

02

Your task

Make #phone a phone field and #email an email field, turn #otp into a text field that brings up the number keypad and accepts only six digits, and give each field the right autocomplete value.

Checks

5 checks
  1. The phone field opens the phone keypad
  2. The email field opens the email keyboard
  3. The code field is a text field with a number keypad, not type="number"
  4. The code accepts only six digits
  5. Each field has the right autocomplete value
03

Hints

0/3
Track lessons0 of 8 done

In this track you'll write your own validation rules, tie one field to another, and write error messages a screen reader can announce.

Intermediate level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/5

Press “Run and check” to grade your code.

5 checks listed under “Your task”.

Track lessons0 of 8 done

In this track you'll write your own validation rules, tie one field to another, and write error messages a screen reader can announce.

Intermediate level, 8 lessons, 1.5 hours in total.