DEV Community

Cover image for HTML Form
Mahalakshmi C
Mahalakshmi C

Posted on

HTML Form

<input> Tag

The <input> tag is one of the most important HTML form elements.

  • It is used to create different types of input fields where users can enter or select data.

  • The behavior of the tag depends on its type attribute. By changing the value of type, the same tag can create a text box, password field, email field, radio button, checkbox, file upload, and many other input controls.

Syntax:

<input type="value">

The type Attribute

  • The type attribute defines what kind of input field the browser should display.

There are many input types available. The most commonly used ones are:

  • text
  • password
  • email
  • number
  • date
  • radio
  • checkbox
  • file
  • submit
  • reset
  • button

type="text"- Creates a single-line text box.

<input type="text">
Enter fullscreen mode Exit fullscreen mode

type="password"- Creates a password field where the entered characters are hidden.

<input type="password">
Enter fullscreen mode Exit fullscreen mode

type="email"- Accepts email addresses and performs basic email validation.

<input type="email">
Enter fullscreen mode Exit fullscreen mode

type="number"- Allows users to enter only numeric values.

<input type="number">
Enter fullscreen mode Exit fullscreen mode

type="date"- Displays a calendar for selecting a date.

<input type="date">
Enter fullscreen mode Exit fullscreen mode

type="radio"- Allows users to select only one option from a group.


<input type="radio" name="gender"> Male

<input type="radio" name="gender"> Female
Enter fullscreen mode Exit fullscreen mode

type="checkbox"- Allows users to select multiple options.

<input type="checkbox"> HTML

<input type="checkbox"> CSS

<input type="checkbox"> JavaScript
Enter fullscreen mode Exit fullscreen mode

type="file"- Allows users to upload files from their device.

<input type="file">
Enter fullscreen mode Exit fullscreen mode

type="submit"- Creates a button that submits the form data to the server.


<input type="submit" value="Register">
Enter fullscreen mode Exit fullscreen mode

type="reset"- Creates a button that clears all form fields.

<input type="reset" value="Clear">
Enter fullscreen mode Exit fullscreen mode

type="button"- Creates a normal button. It does not submit the form unless JavaScript is added.

<input type="button" value="Click Me">
Enter fullscreen mode Exit fullscreen mode

Top comments (0)