totn HTML

HTML: <input> tag

This HTML tutorial explains how to use the HTML element called the <input> tag with syntax and examples.

Description

The HTML <input> tag is an input control that presents users with an interactive control for entering data. Traditionally, the <input> tag is found within the <form> tag and can represent text fields, checkboxes, dropdowns, buttons and other inputs, simply by setting the appropriate type attribute. This tag is also commonly referred to as the <input> element.

Syntax

In HTML, the syntax for the <input> tag is:

<body>
  <form action="" method="get">
    Company: <input type="text" name="company"><br>
    Address: <input type="text" name="address"><br>
    <input type="submit" value="Submit">
  </form>
</body>

Sample Output


Attributes

In addition to the Global Attributes, the following is a list of attributes that are specific to the <input> tag:

Attribute Description HTML Compatibility
autocomplete Value of either on or off to indicate whether the browser can automatically complete the values in the input elements based on values previously entered in the form HTML 4.01, HTML5
autofocus Boolean value indicating that the input should have input focus when the page is loaded, unless the user overrides it. HTML 4.01, HTML5
disabled Boolean value indicating that the user cannot interact with the input. HTML 4.01, HTML5
form Value indicating the form that owns the input. It is the id of a <form> in the same document. HTML 4.01, HTML5
list The id of the <datalist> that provided the list of suggested values for the input HTML 4.01, HTML5
name Name of the input HTML 4.01, HTML5
required Boolean value indicating whether the input is required. Required inputs must be completed before the form can be submitted. HTML 4.01, HTML5
type Type of the input. It can be one of the following values: button, checkbox, color, date, datetime-local, email, file, hidden, image, month, number, password, radio, range, reset, search, submit, tel, text, time, url, week HTML 4.01, HTML5
value Initial value of the input HTML 4.01, HTML5

Note

  • The HTML <input> element is found within the <body> tag. The <input> tag is usually found within the <form> tag.
  • By setting the type attribute, the <input> element can become text fields, checkboxes, radio buttons, dropdowns, buttons, password fields and so much more!

Browser Compatibility

The <input> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <input> tag below, exploring examples of how to use the <input> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.