HTML Input Element Types

HTML Input Element Types

HTML Input Types

HTML provides several types of form inputs, which allow users to enter and interact with data. Some of the most common input types include:

Text Input

Text input allows users to enter and edit text. It is the default input type and is denoted by the input element with no type attribute specified, or with a type attribute set to "text".

<!-- A simple text input -->
<input type="text">

Number Input

Number input allows users to enter and edit numerical values. It is denoted by the input element with a type attribute set to "number".

<!-- A number input with a minimum value of 0 and a maximum value of 100 -->
<input type="number" min="0" max="100">

Password Input

Password input allows users to enter and edit password values. It is denoted by the input element with a type attribute set to "password".

<!-- A password input -->
<input type="password">

Radio Button

Radio buttons allow users to select a single option from a group of options. They are denoted by the input element with a type attribute set to "radio", and are typically used in conjunction with the label element.

<!-- A group of radio buttons -->
<label>
  <input type="radio" name="color" value="red"> Red
</label>
<label>
  <input type="radio" name="color" value="green"> Green
</label>
<label>
  <input type="radio" name="color" value="blue"> Blue
</label>

Checkbox

Checkboxes allow users to select one or more options from a group of options. They are denoted by the input element with a type attribute set to "checkbox", and are typically used in conjunction with the label element.

<!-- A group of checkboxes -->
<label>
  <input type="checkbox" name="fruit" value="apple"> Apple
</label>
<label>
  <input type="checkbox" name="fruit" value="orange"> Orange
</label>
<label>
  <input type="checkbox" name="fruit" value="banana"> Banana
</label>

Dropdown

Dropdowns allow users to select a single option from a list of options. They are denoted by the select element and the option element.

<!-- A dropdown -->
<select>
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
</select>

Textarea

Textarea allows users to enter and edit multi-line text. It is denoted by the textarea element.

<!-- A textarea -->
<textarea></textarea>

Hidden Input

Hidden input allows users to store data that is not visible to the user. It is denoted by the input element with a type attribute set to "hidden".

<!-- A hidden input -->
<input type="hidden" name="user_id" value="123">

Button

The button allows users to trigger an action, such as submitting a form or resetting form values. It is denoted by the button element.

<!-- A button -->
<button type="button">Click me</button>

Image Input

Image input allows users to select an image to upload. It is denoted by the input element with a type attribute set to "image".

<!-- An image input -->
<input type="image" src="image.jpg" alt="Submit">

It's important to note that all form inputs should be used within a form element in order to properly submit data to a server.

<form action="/submit">
  <!-- Form inputs go here -->
</form>

Date Input

Date input allows users to enter and edit date values. It is denoted by the input element with a type attribute set to "date".

<!-- A date input with a minimum value of today and a maximum value of one year from today -->
<input type="date" min="today" max="1 year">

Time Input

Time input allows users to enter and edit time values. It is denoted by the input element with a type attribute set to "time".

<!-- A time input with a minimum value of 8:00am and a maximum value of 5:00pm -->
<input type="time" min="8:00" max="17:00">

Email Input

Email input allows users to enter and edit email addresses. It is denoted by the input element with a type attribute set to "email".

<!-- An email input -->
<input type="email">

URL Input

URL input allows users to enter and edit URLs. It is denoted by the input element with a type attribute set to "url".

<!-- A URL input -->
<input type="url">

Range Input

Range input allows users to select a value within a range of values. It is denoted by the input element with a type attribute set to "range".

<!-- A range input with a minimum value of 0 and a maximum value of 100 -->
<input type="range" min="0" max="100">

Search Input

Search input allows users to enter and edit search queries. It is denoted by the input element with a type attribute set to "search".

<!-- A search input -->
<input type="search">

Tel Input

Tel input allows users to enter and edit telephone numbers. It is denoted by the input element with a type attribute set to "tel".

<!-- A tel input -->
<input type="tel">

Color Input

Color input allows users to select a color value. It is denoted by the input element with a type attribute set to "color".

<!-- A color input -->
<input type="color">

Datetime Input

Datetime input allows users to enter and edit date and time values. It is denoted by the input element with a type attribute set to "datetime".

<!-- A datetime input with a minimum value of today at 8:00am and a maximum value of one year from today at 5:00pm -->
<input type="datetime" min="today 8:00" max="1 year 17:00">

In conclusion, HTML provides a variety of input types that allow users to enter and interact with data in forms. These input types include text, number, password, radio buttons, checkboxes, dropdowns, textarea, file, hidden, button, image, date, time, email, URL, range, search, tel, color, datetime, datetime-local, month, week, and file (multiple). By using the appropriate input type for the type of data being collected, you can create user-friendly and effective forms for your users.