Form Elements in HTML: A Guide to Creating Interactive Forms


Introduction

Creating forms in HTML is an essential part of web development. It allows users to interact with a website by providing input and submitting data. In this blog post, we will cover the basics of creating forms in HTML, including the different form elements and how to use them.

Form Element

The form element is the container for all the form controls. It is used to create an area where users can input data and submit it to the server. The form element has two attributes: action and method. The action attribute specifies the URL of the file that will process the form data, and the method attribute specifies how the data will be sent to the server (GET or POST).

Input Elements:

There are several types of input elements that can be used within a form, including text, radio, checkbox, select, and textarea.

  • The text input element allows users to enter a single line of text.
  • The radio input element allows users to select one option from a group of options.
  • The checkbox input element allows users to select multiple options from a group of options.
  • The select input element allows users to select one option from a dropdown list.
  • The textarea input element allows users to enter multiple lines of text.

Submit Button:

The submit button is used to submit the form data to the server. It is important to note that without a submit button, the form data cannot be sent. The submit input element is used to create the button, and it has an attribute called value which specifies the text that will appear on the button.

Here is the simple program for printing the form element example in html

Source Code

<html>
  <head>
    <title>Tutor Joes</title>
  </head>
  <body>
    <h1>Form Element in HTML</h1>
    <form>
  <fieldset>
    <legend>Registeration Form:</legend>
    <label for="fname">First name:</label><br>
    <input type="text" id="fname" name="fname" value="Tutor"><br>
    <label for="lname">Last name:</label><br>
    <input type="text" id="lname" name="lname" value="Joe's"><br>
    <label for="email">Email ID:</label><br>
    <input type="email" id="email" name="email" value="sample@gamil.com"><br>        
    <label for="mobileNo">Mobile No.:</label><br>
    <input type="text" id="mobileNo" name="mobileNo" value="9988776655"><br>        
    <label for="address">Address:</label><br> 
    <textarea type="text" name="address" rows="5" cols="23">
    Salem
    </textarea>
    <input type="submit" value="Submit">
  </fieldset>
</form>
  </body>
</html>
To download raw file Click Here

The code you provided creates an HTML document with a title of "Tutor Joes". The body of the document contains a heading with the text "Form Element in HTML".

  • Within the body, there is a form element which contains a fieldset element with a legend element that reads "Registration Form".
  • Inside the fieldset element, there are several label, input, and textarea elements.
  • The label elements are used to create a caption for each corresponding input field.
  • The input elements of type "text" and "email" are used to create text fields for the user to enter their first and last name, email address and mobile number.
  • The textarea element is used to create a multi-line text input area for the user to enter their address.
  • The input element of type "submit" is used to create a button that the user can click on to submit the form.

Conclusion:

Creating forms in HTML is an essential part of web development. Understanding the different form elements and how to use them can help you create more interactive and user-friendly websites. With this guide, you now have the basic knowledge to create forms in HTML and take your web development skills to the next level.