HTML5 Forms

Level : Intermediate
Mentor: Shailendra Chauhan
Duration : 00:02:30

Input Element:

The input element is a fundamental form element that enables users to input various types of data such as text, numbers, checkboxes, etc.

Example:

<input type="text" name="username" placeholder="Enter your username">

Text Type:

The text type is an input element used for single-line text input, such as names, emails, or passwords.

Example:

<input type="text" name="name" placeholder="Enter your name">

Checkbox Type:

The checkbox type is a form element that allows users to select multiple options from a list. It presents a box that can be checked or unchecked to indicate a choice.

Example:

<input type="checkbox" name="fruits" value="apple"> Apple
<input type="checkbox" name="fruits" value="banana"> Banana
<input type="checkbox" name="fruits" value="orange"> Orange

Radio Button Type:

The radio button type is an input element that allows users to choose only one option from a list of mutually exclusive choices.

Example:

<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female

Number Type:

The number type is an input element that allows users to enter numeric values, optionally with specified minimum and maximum constraints.

Example:

<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" min="1" max="10">

Password Type:

The password type is an input element that allows users to enter a secure, masked password.

Example:

<input type="password" name="password" placeholder="Enter your password">

Textarea Element:

The textarea element is used to create a multiline text input field, allowing users to enter longer text or comments.

Example:

<textarea name="message" rows="4" cols="50">Enter your message here…</textarea>

Select Element:

The select element creates a dropdown list from which users can choose one option.

Example:

<select name="country">
  <option value="usa">USA</option>
  <option value="uk">UK</option>
  <option value="canada">Canada</option>
</select>

Datalist Element:

The datalist element provides a list of predefined options for an input element with an autocomplete feature.

Example:

<input list="colors" name="color">
<datalist id="colors">
  <option value="Red">
  <option value="Blue">
  <option value="Green">
</datalist>

Label Element:

The label element provides a label or description for form elements, improving accessibility and user experience.

Example:

<label for="username">Username:</label>
<input type="text" id="username" name="username">

Form Element:

The form element is used to create a container for other form elements, enabling users to input and submit data to a server.

Example:

<form action="/submit_form" method="post">
  <!-- Form elements go here -->
</form>

Submittable Input:

A submittable input is any form element that allows users to provide data to be submitted when the form is submitted.

Example:

<input type="text" name="email" placeholder="Enter your email" required>

Input name Attribute:

The name attribute is used to associate a form element's value with the data that will be sent to the server upon form submission.

Example:

<input type="text" name="username" placeholder="Enter your username">

required Attribute:

The required attribute is used to indicate that a form element must be filled out before the form can be submitted.

Example:

<input type="text" name="name" placeholder="Enter your name" required>

max Attribute:

The max attribute is used to specify the maximum value allowed for number inputs or dates.

Example:

<input type="number" name="age" max="100">

min Attribute:

The min attribute sets the minimum value allowed for number inputs or dates.

Example:

<input type="number" name="quantity" min="1">

minlength Attribute:

The minlength attribute sets the minimum number of characters required for a text-based form element.

Example:

<input type="text" name="username" minlength="5" placeholder="Enter at least 5 characters">

maxlength Attribute:

The maxlength attribute sets the maximum number of characters a user can input in a text-based form element.

Example:

<input type="text" name="message" maxlength="100">

pattern Attribute:

The pattern attribute is used to enforce a specific regex pattern for input validation.

Example:

<input type="text" name="zip" pattern="[0-9]{5}" title="Five-digit zip code">

Range Type:

The range type is an input element that allows users to select a value from a specified range using a slider.

Example:

<label for="volume">Volume:</label>
<input type="range" id="volume" name="volume" min="0" max="100">

Submitting a Form:

Submitting a form is the process of sending data entered by the user to the server for processing or storage.

Example:

<form action="/submit_form" method="post">
  <!-- Form elements go here -->
  <input type="submit" value="Submit">
</form>

HTML Form Validators:

HTML5 provides built-in form validation using attributes like required, pattern, min, max, etc., to enforce data correctness.

Example:

<input type="email" name="email" placeholder="Enter your email" required>
<input type="date" name="dob" max="2003-01-01">
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this