HTML input tag

What Is the HTML Input Element (<input>) and How Is It Used?

Through input <input> element you can get inputs from the users in a variety of tools available in HTML. The most important thing about input tag, it provides various different kind of graphical user interfaces such as drop-down list boxes, radio buttons (also called option buttons), text input boxes, check boxes, image buttons, submit buttons etc. You can use these input tools as per your requirements in form designing. You can design different kind of input elements through changing type attribute of input tag. Example


Enter your name: <input type="text" name="name" id="name" />
Output

Enter your name: 
Attribute Description
Id Through id attribute you can identify the input field in your HTML file. Multiple input fields in an HTML file can be possible so in this condition you can easily identify input fields through their ids.

id="input_ele_id"
Name Through name attribute you can identify the input field in your html file. Multiple input fields in an HTML file can be possible so in this condition you can easily identify input fields through their names.

name="input_ele_name"
Align This attribute is used only with image type input tool. All the valid values are top middle and bottom.
Maxlength This attribute sets the maximum length of characters can be input by the user. If you do not set maxlength attribute then default value remain unlimited. This attribute you can set only for text type input tool.
Size Specify the text type input field's width. If number of characters are more than the specify size of the input field then text would be scrollable.
Checked This attribute is used only with radio and checkbox type input tool. It selects the radio buttons and check boxes. If you do not set this attribute then default it remains unselected.
Src It defines the path of the image. This attribute set only with image type tool.
Value This attribute set the value for input fields.
Type Type attribute define which kind of input field will be designed for the user. All possible values for type attribute are mentioned below:
  • Checkbox: It creates checkboxes. When you want to gather data that can have multiple options at a time. User can select multiple option at the same time.
  • Hidden: Hidden input field does not appear at browser. You can set any value in hidden field which you do not want to show at browser. But want to use in your program.
  • Text: Text field user for getting single line text input from your users. Text type input field uses size and maxlength attributes, through these attributes you can set size and maxlentgh of characters.
  • Password: It is a kind of field where you can get input data from users in a secret manner. Whatever user enter from keyboard in password field it will not appear as same as he/she enters rather then it appear in similar kind of characters such as * (asterisk) sign. It use for security purpose for critical data.
  • Radio: It creates radio buttons. When you required getting input only one option out of many option, so for it you can set type attribute as radio.
  • Reset: It reset a form to its default values. Which appear at the time of loading your webpage. The value attribute of reset button appear on the button.
  • Submit: It submit a form and send data to server. The value attribute set the string which appear on the submit button.
  • Image: It also works like submit button. You can set image on this tool through src attribute. Through image button you can include image. So you can create more attractive buttons through this element.
  • File: Through file type tool you can upload files.

FAQ 1. What is the purpose of the type attribute in an HTML input element? The type attribute determines how an input field behaves and appears in the browser. For example, type="text" creates a text field, while type="password" creates a field that masks the entered characters. 2. What is the difference between text and password input types in HTML? The text input type displays the characters entered by the user normally. The password input type hides the entered characters visually, making it suitable for password entry fields.