HTML Input Types

HTML Living Standard

The type attribute controls what kind of input the browser shows and which values it accepts. HTML defines 22 current input types. Pick one by the kind of information you want to collect or the action the control should perform.

On this page

Text and contact fields

  • Text input (type="text")

    Use a single-line text field for names and other short text. The text type is also the default when type is omitted.

  • Search field (type="search")

    Collect a search query in a single line. Some browsers add a clear button.

  • Telephone input (type="tel")

    Collect a phone number. A mobile browser can show a telephone keyboard. Add a suitable pattern if you require a particular format.

  • URL input (type="url")

    Collect a web address. A nonempty value must have a valid absolute URL format to pass native validation.

  • Email input (type="email")

    Collect an email address and check its format in the browser. The format check cannot confirm that an inbox exists.

  • Password input (type="password")

    Hide the characters while the user types. Use login or signup autocomplete hints so password managers can help.

Date and time fields

Numbers and pickers

Choices and files

Form actions and hidden values

Collect several lines with <textarea>

A textarea accepts line breaks. rows sets the initial visible height in lines. Put initial text between the tags. In JavaScript, read the current editable text from .value.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Collect several lines with &lt;textarea&gt;</title>
</head>
<body>
<label for="note">Order note</label><br>
<textarea id="note" name="note" rows="3">Less sugar</textarea>
<pre id="result"></pre>
  <script>
const note = document.querySelector("#note");
const preview = () => document.querySelector("#result").textContent = note.value;
note.addEventListener("input", preview);
preview();
  </script>
</body>
</html>

What to expect Edit the note and add a new line. The text below updates immediately.

Related lessons

Official references