View video tutorial

HTML Form Elements

HTML

Form elements are the elements carries the individual information.

Common HTML form elements

<input>, <option>, <label>, <button>, <textarea> etc.

Form element <input>


This is one of the most and widely used form element in a plain text.

type attribute of <input> element determines the input type and behaviour of the element.

Most common input types are text, radio, checkbox, date, color, email, file, password, button, submit etc.

Example

<!DOCTYPE html>
<html>

<head>
   <title>HTML Form Example</title>
   <meta charset="utf-8" />
</head>

<body>

   <h2>Form Example</h2>

   <form action="" method="get" class="form-example">
      <div class="form-group">
         <label for="name">Enter your name: </label>
         <input type="text" name="name" id="name" required>
      </div>
      <div class="form-group">
         <label for="email">Enter your email: </label>
         <input type="email" name="email" id="email" required>
      </div>
      <div class="form-group">
         <input type="submit" value="Subscribe!">
      </div>
   </form>
</body>

</html>
Try it Now »

Click on the "See output" button to see how it works.


Form element <label>


<label> element specify the label of input element.

for attribute of <label> element must match to the id attribute of <input> element.

When the user clicks on the text of <label>, input element get focused and act accordingly.

Example

<!DOCTYPE html>
<html>

<head>
   <title>HTML Form Example</title>
   <meta charset="utf-8" />
</head>

<body>

   <h2>Form Example</h2>

   <form action="" method="get" class="form-example">
      <div class="form-group">
         <label for="name">Enter your name: </label>
         <input type="text" name="name" id="name" required>
      </div>
      <div class="form-group">
         <label for="email">Enter your email: </label>
         <input type="email" name="email" id="email" required>
      </div>
      <div class="form-group">
         <input type="submit" value="Subscribe!">
      </div>
   </form>
</body>

</html>
Try it Now »

Click on the "See output" button to see how it works.