Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. HTML Tag Dictionary
  3. <input> — Text

<input> — Text

The text-type variants of <input> create a single-line text input field. By specifying the input type via the type attribute, the browser automatically provides an appropriate keyboard and validation.

Syntax

<input type="text" name="field-name" placeholder="hint text" value="default value">

type values (text-based)

type valueDescription
textA single-line text input field. The most basic type, with no restrictions on what can be entered.
passwordA password input field where characters are masked with dots or asterisks.
emailAn input field for email addresses. The browser validates the format on submission.
urlAn input field for URLs. The browser checks for a valid format such as https:// on submission.
telAn input field for telephone numbers. On smartphones, a numeric keyboard is displayed.
searchAn input field for search keywords. Some browsers display a clear (×) button.

Common attributes

AttributeDescription
nameSpecifies the key name for the data when the form is submitted. The server receives the data under this name.
valueSpecifies the initial value of the input field.
placeholderSpecifies hint text displayed in light gray when the field is empty.
requiredMakes the field required. An error is shown if you try to submit the form with this field empty.
maxlengthSpecifies the maximum number of characters that can be entered.
minlengthSpecifies the minimum number of characters required.
readonlyMakes the field read-only. The user cannot edit it, but its value is still included in the submitted data.
disabledDisables the field. The user cannot interact with it, and its value is not included in the submitted data.
autocompleteControls the browser's autocomplete behavior. Accepts values such as on (enabled) and off (disabled).
patternSpecifies a validation rule using a regular expression. If the value does not match, submission fails.

Sample code

<form action="/register.php" method="post">

  <!-- Text input -->
  <div>
    <label for="username">Username</label>
    <input type="text" id="username" name="username"
      placeholder="e.g. yamada_taro" maxlength="20" required>
  </div>

  <!-- Password input -->
  <div>
    <label for="password">Password (8 characters or more)</label>
    <input type="password" id="password" name="password"
      minlength="8" required autocomplete="new-password">
  </div>

  <!-- Email input -->
  <div>
    <label for="email">Email address</label>
    <input type="email" id="email" name="email"
      placeholder="example@example.com" required>
  </div>

  <!-- Phone number input -->
  <div>
    <label for="tel">Phone number</label>
    <input type="tel" id="tel" name="tel"
      placeholder="090-0000-0000"
      pattern="[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}">
  </div>

  <!-- URL input -->
  <div>
    <label for="website">Website</label>
    <input type="url" id="website" name="website"
      placeholder="https://example.com">
  </div>

  <!-- Search box -->
  <div>
    <label for="keyword">Keyword search</label>
    <input type="search" id="keyword" name="q"
      placeholder="Enter a search keyword">
  </div>

  <button type="submit">Register</button>

</form>

Result

Six input fields are displayed — username, password, email address, phone number, URL, and search — along with a Register button. Characters typed into the password field are masked, and the email field is validated on submission. On smartphones, tapping the phone number field brings up a numeric keyboard.

Notes

By specifying an appropriate value for the type attribute, the browser automatically performs validation. For example, type="email" checks that the value contains an @ symbol, and type="url" checks that it starts with http:// or https://. However, browser-side validation is only supplementary. Always validate input on the server side as well.

Always associate <label> with <input> using the for and id attributes. This ensures that clicking the label moves focus to the field, and that screen readers announce it correctly.

For the form container, see 『form』.

Browser Support

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
Supported in all versions
Safari Safari
18+
Supported in all versions
Edge Edge
80+
11 or earlier ×
IE IE
11 or earlier ×
Opera Opera
48+
14 or earlier ×
iOS Safari iOS Safari
18+
Supported in all versions
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .