You made a field for typing text with <input type="text">. Changing type changes its form, remember? This lesson picks up from there. Let’s learn a few input fields suited to their purpose.
Trying out different types
Here are some frequently used type values, lined up.
<input type="text">
<input type="password">
<input type="email">
<input type="number">| type | What kind of field it becomes |
|---|---|
text | An ordinary one-line input |
password | The typed characters are hidden as ●●● |
email | For email (on a phone, the keyboard puts @ within reach) |
number | Numbers only (with up/down buttons) |
tel | For phone numbers (on a phone, a number keypad tends to come up) |
date | Becomes a field where you pick a date from a calendar |
Even the same <input> changes this much with a single type. For now, it’s enough to just know “there’s a family of these.”
Showing a faint example with placeholder
You can show an input example in an input field, in faint text. That’s placeholder.
<input type="text" placeholder="Enter your name">It gently answers the question “what should I write here?” As soon as you start typing, it vanishes.
Long text goes in <textarea>
<input> is one line only. When you want to write several lines, like a comment or a message, you use <textarea>.
<textarea placeholder="Share your thoughts"></textarea><input>, you can write with line breaks.Give it a try
How much does an input field change its form when you change type? Let’s see for ourselves with the real thing. Sliders and color pickers are fun to play with.
<input>, yet a single type changes it this much. Getting to drag the range slider and pick a color with color is part of the fun of type.Summary of this lesson
<input>changes the kind of input field when you changetype(password, email, number…)- With
placeholder, you can show a faint-text example - Long text goes in
<textarea>~</textarea>(write the closing tag too)
