×

HTML Form Input Types

HTML Form Input Types

An important element of the HTML form is < input type= "> in HTML. The type attribute of the input element can be of different types, which defines the information field. For example, < input type="text "name="name" > gives a text box.

The following is a list of all types of HTML element < input>.

Type=“ ”Description
passwordDefine the input field of a single line password.
radioDefines a radio button that allows one of the choices to be selected.
resetDefines a reset button in the form to restore all the values.
checkboxDefines checkboxes that allow multiple options of type to be selected.
buttonDefine a basic push button which can be programmed to accomplish an event mission.
fileDefines the file to be picked from system storage.
imageSets a graphic submission button.
submitDefines the button to submit the form to the server.
textDefines a single-line text input field

HTML5 has introduced new styles on the element < input>. Below is a list of types of HTML5 elements

TypeDescription
ColorDefine a common color field for the data.
DateDefines the input field for the selection of dates.
datetime-localDefines an input field for entering a date without a time zone.
EmailDefines an entry field for an email address to enter.
MonthDefine a rule for the month and year, without time zone.
NumberSets a field input for entering a number.
urlSets a field to access URL
WeekDefines a area with week-year, without time zone to reach the year.
SearchDefines the text field of a single line to enter a search string.

The definition with examples of types of < input > elements follows.

1. <input type="password">:

The "password" form feature < input > enables a user to safely enter the password in a web page. The password-filed text entered is translated to "*" or.", "so that another person can't read it.

Example:

<form>       
<label>Enter User name</label><br>       
<input type="text" name="name"><br>       
<label>Enter Password</label><br>       
<input type="Password" name="password"><br>       
<br><input type="submit" value="submit">   
</form>  

Output:

HTML Form Input Types

2.  <input type="submit">:

The "submit" type item < input > specifies a submit button when the "press" event occurs to submit the form to the server.

Example

<form>       
<label>Enter User name</label><br>       
<input type="text" name="firstname"><br>       
<label>Enter Password</label><br>       
<input type="Password" name="password"><br>  <br>
<input type="submit" value="submit">   
</form>  

Output

HTML Form Input Types

Upon clicking the submit button, the form will be submitted to the server and the page will be redirected to the action value.

3. <input type="text">:

The "text" type element < input > is used to define a text field in a single line.

Example:

<form>       
<label>Enter first name</label><br>       
<input type="text" name="firstname"><br>       
<label>Enter last name</label><br>       
<input type="text" name="lastname"><br>       
<p><strong>Note:</strong>The default maximum cahracter lenght is 20.</p>   
</form>    

Output:

HTML Form Input Types

4. <input type="radio">:

The radio buttons are specified by the < input > type "radio" which allows choosing an option between collections of related options. Only one radio-button option at a time can be selected.

Example:

<form> <p>Kindly Select your favorite color</p> 
<input type="radio" name="color" value="purple"> purple <br> 
<input type="radio" name="color" value="green"> green <br> 
<input type="radio" name="color" value="pink"> pink <br> 
<input type="radio" name="color" value="blue"> blue <br> 
<input type="submit" value="submit"> 
</form>  

Output:

HTML Form Input Types

5. <input type="reset">:

The < input > type "reset" is often known as a button, but when the user performs a click event, the default is to reset all input values.

Example:

<form> <label>User id: </label> 
<input type="text" name="user-id" value="user"> 
<label>Password: </label> 
<input type="password" name="pass" value="pass"><br><br> 
<input type="submit" value="login"> 
<input type="reset" value="Reset"> 
</form>

Output:

HTML Form Input Types

6. <input type="checkbox">:

The < input > form "checkbox" is shown as square boxes that can be checked or unchecked to pick a choice from a given selection.

Example:

<form> <label>Enter your Name:</label> 
<input type="text" name="name"> 
<p>Kindly Select your favourite sports</p>             
<input type="checkbox" name="sport1" value="football">Football<br> 
<input type="checkbox" name="sport2" value="badminton">Badminton<br><br>             
<input type="checkbox" name="sport3" value="tennis">Tennis<br> 
<input type="checkbox" name="sport4" value="cricket">Cricket<br>             
<input type="checkbox" name="sport5" value="baseball">Baseball<br> 
<input type="submit" value="submit"> 
</form>

Output:

HTML Form Input Types

7. <input type="button">:

The < input > type "button" describes a simple push button that can be programmed to control any event, such as clicking an action.

<form> <input type="button" value="Clcik me " onclick="alert('you are learning HTML')"> </form>

Output:

HTML Form Input Types

8. <input type="file">:

The < Input > file type element is used to select one or more files from the storage device of the user. If the file is selected and uploaded, it can be uploaded to the server using the JS code and file API.

Example:

<!DOCTYPE html> 
<html> 
<body>             
<h2>Input "file" type.</h2>             
<p>We can choose any type of file until we do not specify it! The selected file will appear at next to "choose file" option</p> 
<form> <label>Select file to upload:</label> 
<input type="file" name="newfile"> 
<input type="submit" value="submit"> 
</form> 
</body> 
</html>

Output:

HTML Form Input Types

9. <input type="image">:

The "image" type < input > is used in file form to represent a submit button.

Example:

<!DOCTYPE html> 
<html> 
<body> 
<h2>Input "image" type.</h2> 
<p>We can create an image as submit button</p> 
<form> 
<label>User id:</label><br> 
<input type="text" name="name"><br><br> 
<input type="image" alt="Submit" src="login.png"  width="100px"> 
</form> 
</body> 
</html>

Output:

HTML Form Input Types

HTML5 newly added <input> types element

1. <input type="color">:

The < input > type "color" is used to define an input field containing a color. It allows the user to specify the color on the browser using visual color interface.

Example:

<form>     Pick your Favorite color: <br><br> 
<input type="color" name="upclick" value="#a52a2a"> Upclick<br><br> 
<input type="color" name="downclick" value="#f5f5dc"> Downclick  
</form>  

Output:

HTML Form Input Types

2. <input type="date">:

The < input > element of type "date" generates an input field, which allows the user to enter a date in a given format. You can enter a date by text field or by date picker interface.

Example:

<form> Select Start and End Date: <br><br>                         
<input type="date" name="Startdate"> Start date:<br><br>     
<input type="date" name="Enddate"> End date:<br><br> 
<input type="submit"> 
</form>

Output:

HTML Form Input Types

3. <input type="datetime-local">:

The < input > element of the type "datetime-local" creates an input filed that allows the user to select the date as well as the local time in the hour and minute without time zone information.

Example:

<form> 
<label>  Select the meeting schedule:   Select date & time: 
<input type="datetime-local" name="meetingdate"><br><br> 
</label> 
<input type="submit"> 
</form>  

Output:

HTML Form Input Types

4. <input type="email">:

The < input > type "email" creates an input filed that allows the user to enter an e-mail address with a pattern validation. Multiple attributes make it possible for a user to enter more than one email address.

Example:

<form> 
<label><b>Enter your Email-address</b></label> 
<input type="email" name="email" required> <input type="submit"> 
<p><strong>Note:</strong>User can also enter multiple email addresses separating by comma or whitespace as following: </p> 
<label><b>Enter multiple Email-addresses</b></label> 
<input type="email" name="email"  multiple> 
<input type="submit"> 
</form>

Output:

HTML Form Input Types

5. <input type="month">:

The < input > type "month" creates an input field that allows the user to easily enter month and year in the "MM, YYYY" format where MM defines the value of the month and YYYY defines the value of the year.

Example:

<form> 
<label>Enter your Birth Month-year: </label> 
<input type="month" name="newMonth"> 
<input type="submit"> 
</form>

Output:

HTML Form Input Types

6. <input type="number">:

The < input > element type number generates an input field that allows the user to enter a numeric value. You can also restrict yourself to enter the minimum and maximum values using the min and max attributes.

Example:

<form> <label>Enter your age: </label> <input type="number" name="num" min="50" max="80"> <input type="submit"> </form>

Output:

HTML Form Input Types

7. <input type="url">:

The < input > element of the type "url" creates an input filed that enables the user to enter the URL.

Example:

<form> <label>Enter your website URL: </label> 
<input type="url" name="website" placeholder="http://example.com"><br> 
<input type="submit" value="send data"> </form>

Output:

HTML Form Input Types

8. <input type="week">:

Form week < input > creates an input field that allows a user to pick a week and year without time zone in the drop-down calendar.

Example:

<form> <label><b>Select your best week of year:</b></label><br><br> 
<input type="week" name="bestweek"> 
<input type="submit" value="Send data"> 
</form>

 

Output:

HTML Form Input Types

The "search" form <input> generates a filed input which enables a user to enter a search string. They are functionally symmetrical to the form of text input but may be different in style.

Example:

<form> <label>Search here:</label> 
<input type="search" name="q"> 
<input type="submit" value="search"> 
</form>

Output:

HTML Form Input Types

Related Topics

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

HTML Audio

HTML AUDIO: HTML5 provides a method to embed the audio file into a webpage by using HTML5. Before HTML5 audio files is used to play on the browser with the help of...

1 minute read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

HTML <body> tag

HTML means Hyper Text Markup Language, which is most preferred for making Web pages. It explains how a Web page is put together. There are many different elements in HTML,...

3 minutes read.

HTML <summary> tag

When we simply want to show the primary heading or topic name of hidden detailed material to users, then we can achieved this by using the summary tag. This makes it...

2 minutes read.

Font tag in HTML

HTML stands for Hypertext Mark-up Language and is used to create web pages and other information that can be later displayed in a web browser. It also consists of a...

4 minutes read.

HTML Code Tag

The code tag in HTML is a phrase tag used to insert a piece of computer programming code. In HTML there is a separate tag named as <code> tag. Sometimes,...

3 minutes read.

HTML &lt;body> alink Attribute

HTML <body> alink Attribute What is HTML? The HTML or HyperText Markup Language is used to design web pages. The file extension name for HTML file is ".html". It was released in...

2 minutes read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 minutes read.

HTML <svg> tag

SVG is used to determine the vector-based graphics in XML format. What is SVG? We utilize SVG tag to specify visuals for the website. The attribute of SVG in a HTML document...

2 minutes read.

HTML Code

Before jumping into the topic, let’s understand a common scenario where we have a code snippet in our HTML file. By code snippet, we mean computer code, which is written...

5 minutes read.

HTML5 Attribute

HTML Attribute HTML attributes are special words that provide additional information about the HTML element or attributes.The element or tags have attributes, which define the element's behavior.It also adds attributes with a start...

3 minutes read.

HTML Form Action

The <form> tag has an attribute named action that contains a URL. The HTML action attribute defines the webpage URL on which you want to send the data after submitting...

4 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

HTML Lists

HTML List HTML lists are used to specify data sets. All lists can include one or more elements from the list. HTML lists are available in three different types: Ordered List or...

4 minutes read.

How to create a link with no underline in HTML

In HTML, an anchor tag (<a>) is a Styled Container tag, which means when a hyperlink is created using this, browsers, by default, display the link by applying some styles...

5 minutes read.

HTML Background Image

Inserting image in HTML An image (technically digital image) in HTML or even in general technical aspects, is a binary representation of visual information. By visual information we mean, in the...

8 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.