DEV Community

wasifali
wasifali

Posted on

6

HTML input types with examples

HTML Input Types

Here are the different input types you can use in HTML:
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">

Input Type Text

<input type="text"> defines a single-line text input field:

Example

<form>
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Password

<input type="password"> defines a password field:

Example

<form>
  <label for="username">Username:</label><br>
  <input type="text" id="username" name="username"><br>
  <label for="pwd">Password:</label><br>
  <input type="password" id="pwd" name="pwd">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Submit

<input type="submit"> defines a button for submitting form data to a form-handler.
The form-handler is specified in the form's action attribute

Example

<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Reset

<input type="reset"> defines a reset button that will reset all form values to their default values

Example

<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Radio

<input type="radio"> defines a radio button.

Example

<form>
  <input type="radio" id="html" name="fav_language" value="HTML">
  <label for="html">HTML</label><br>
  <input type="radio" id="css" name="fav_language" value="CSS">
  <label for="css">CSS</label><br>
  <input type="radio" id="javascript" name="fav_language" value="JavaScript">
  <label for="javascript">JavaScript</label>
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Checkbox

<input type="checkbox"> defines a checkbox.

Example

<form>
  <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
  <label for="vehicle1"> I have a bike</label><br>
  <input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
  <label for="vehicle2"> I have a car</label><br>
  <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
  <label for="vehicle3"> I have a boat</label>
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Button

<input type="button"> defines a button

Example

<input type="button" onclick="alert('Hello World!')" value="Click Me!">
Enter fullscreen mode Exit fullscreen mode

Input Type Color

The <input type="color"> is used for input fields that should contain a color.

Example

<form>
  <label for="favcolor">Select your favorite color:</label>
  <input type="color" id="favcolor" name="favcolor">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Date

The <input type="date"> is used for input fields that should contain a date.

Example

<form>
  <label for="birthday">Birthday:</label>
  <input type="date" id="birthday" name="birthday">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Email

The <input type="email"> is used for input fields that should contain an e-mail address.

Example

<form>
  <label for="email">Enter your email:</label>
  <input type="email" id="email" name="email">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Image

The <input type="image"> defines an image as a submit button.

Example

<form>
<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type File

The <input type="file"> defines a file-select field and a "Browse" button for file uploads.

Example

<form>
  <label for="myfile">Select a file:</label>
  <input type="file" id="myfile" name="myfile">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Hidden

The <input type="hidden"> defines a hidden input field

Example

<form>
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <input type="hidden" id="custId" name="custId" value="3487">
  <input type="submit" value="Submit">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Month

The <input type="month"> allows the user to select a month and year.

Example

<form>
  <label for="bdaymonth">Birthday (month and year):</label>
  <input type="month" id="bdaymonth" name="bdaymonth">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Number

The <input type="number"> defines a numeric input field.

Example

<form>
  <label for="quantity">Quantity (between 1 and 5):</label>
  <input type="number" id="quantity" name="quantity" min="1" max="5">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Search

The <input type="search"> is used for search fields

Example

<form>
  <label for="gsearch">Search Google:</label>
  <input type="search" id="gsearch" name="gsearch">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Tel

The <input type="tel"> is used for input fields that should contain a telephone number.

Example

<form>
  <label for="phone">Enter your phone number:</label>
  <input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Time

The <input type="time"> allows the user to select a time (no time zone).

Example

<form>
  <label for="appt">Select a time:</label>
  <input type="time" id="appt" name="appt">
</form>
Enter fullscreen mode Exit fullscreen mode

Input Type Url

The <input type="url"> is used for input fields that should contain a URL address.

Example

<form>
  <label for="homepage">Add your homepage:</label>
  <input type="url" id="homepage" name="homepage">
</form>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

šŸ‘‹ Kindness is contagious

Please leave a ā¤ļø or a friendly comment on this post if you found it helpful!

Okay