How to create an html form for user input?

What is HTML Form : 
HTML Form is a document which stores information of a user on a web server using interactive controls. An HTML form contains different kind of information such as username, password, contact number, email id etc. 
The elements used in an HTML form are check box, input box, radio buttons, submit buttons etc. Using these elements the information of an user is submitted on a web server.
The form tag is used to create an HTML form.
 

Example of an HTML Form :

html

<!DOCTYPE html>

<html>

<body>

<form>

  Username:<br>

  <input type="text" name="username">

  <br>

  Email id:<br>

  <input type="text" name="email_id">

  <br><br>

  <input type="submit" value="Submit">

</form>

</body>

</html>

Output : 
 

How to create an html form for user input?

Input Element in HTML Forms :

Input Elements are the most common elements which are used in HTML Forms. Various user input fields can be created such as textfield, check box, password field, radio button, submit button etc. The most common input elements are listed below:
 

  1. Text Field in HTML Forms : 
    The text field is a one line input field allowing the user to input text. Text Field input controls are created using the “input” element with a type attribute having value as “text”.
     

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example Of Text Field</h3>

    <form>

        <label for="EMAIL ID">Email Id:</label><br>

        <input type="text" name="Email id" id="Email id">

    </form>

</body>

</html>

Output:

How to create an html form for user input?

  1.  
  2. Password Field in HTML Forms : 
    Password fields are a type of text field in which the text entered is masked using asterisk or dots for prevention of user identity from another person who is looking onto the screen. Password Field input controls are created using the “input” element with a type attribute having value as “password”.
     

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of Password Field</h3>   

    <form>

        <label for="user-password">Password:

        </label><br>

        <input type="password" name="user-pwd"

                            id="user-password">

    </form>

</body>

</html>

  1. Output : 
     

How to create an html form for user input?

  1.  
  2. Radio Buttons in HTML Form : 
    Radio Buttons are used to let the user select exactly one option from a list of predefined options. Radio Button input controls are created using the “input” element with a type attribute having value as “radio”.
     

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of Radio Buttons</h3>

    <form>

        SELECT GENDER

        <br>

        <input type="radio" name="gender" id="male">

        <label for="male">Male</label><br>

        <input type="radio" name="gender" id="female">

        <label for="female">Female</label>

    </form>

</body>

</html>

  1. Output : 
     

How to create an html form for user input?

  1.  
  2. Checkboxes in HTML Form : 
    Checkboxes are used to let the user select one or more options from a pre-defined set of options. Checkbox input controls are created using the “input” element with a type attribute having value as “checkbox”.
     

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of HTML Checkboxes</h3>

    <form>

        <b>SELECT SUBJECTS</b>

        <br>

        <input type="checkbox" name="subject" id="maths">

        <label for="maths">Maths</label>

        <input type="checkbox" name="subject" id="science">

        <label for="science">Science</label>

        <input type="checkbox" name="subject" id="english">

        <label for="english">English</label>

    </form>

</body>

</html>

  1. Output : 
     

How to create an html form for user input?

  1.  

File select boxes in HTML Forms :

File select boxes are used to allow the user to select a local file and send it as an attachment to the web server.It is similar to a text box with a button which allows the user to browse for a file.Instead of browsing for the file, the path and the name of the file can also be written. File select boxes are created using the “input” element with a type attribute having value as “file”.
 

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of a File Select Box</h3>

    <form>

        <label for="fileselect">Upload:</label>

        <input type="file" name="upload" id="fileselect">

    </form>

</body>

</html>

Output : 
 

How to create an html form for user input?

Text area in an HTML Form :

Text Area is a multiple line text input control which allows user to provide a description or text in multiple lines. A Text Area input control is created using the “textarea” element.
 

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of a Text Area Box</h3>

    <form>

        <label for="Description">Description:</label>

        <textarea rows="5" cols="50" name="Description"

                            id="Description"></textarea>

    </form>

</body>

</html>

Output : 
 

How to create an html form for user input?

Select Boxes in HTML Forms :

Select boxes are used to allow users to select one or more than one option from a pull-down list of options. Select boxes are created using two elements which are “select” and “option”.List items are defined within the select element.
 

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of a Select Box</h3>

    <form>

        <label for="country">Country:</label>

        <select name="country" id="country">

            <option value="India">India</option>

            <option value="Sri Lanka">Sri Lanka</option>

            <option value="Australia">Australia</option>

        </select>

    </form>

</body>

</html>

Output :
 

How to create an html form for user input?

How to create an html form for user input?

Reset And Submit Buttons :

The Submit Button allows the user to send the form data to the web server. The Reset Button is used to reset the form data and use the default values.
 

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of a Submit And Reset Button</h3>

    <form action="test.php" method="post" id="users">

        <label for="username">Username:</label>

        <input type="text" name="username" id="Username">

        <input type="submit" value="Submit">

        <input type="reset" value="Reset">

    </form>

</body>

</html>

Output : 
 

How to create an html form for user input?

Attributes Used in HTML Forms

The Action Attribute : 
The action to be performed after the submission of the form is decided by the action attribute. Generally, the form data is sent to a webpage on the web server after the user clicks on the submit button.
Example : 
 

How to create an html form for user input?

html

<!DOCTYPE html>

<html>

<body>

    <h3>Example of a Submit And Reset Button</h3>

    <form action="test.php" method="post" id="users">

        <label for="username">Username:</label>

        <input type="text" name="username" id="Username">

        <input type="submit" value="Submit">

        <input type="reset" value="Reset">

    </form>

</body>

</html>

If you click the submit button, the form data
would be sent to a page called test.php .

The Target Attribute in HTML Forms : 
The Target attribute is used to specify whether the submitted result will open in the current window, a new tab or on a new frame. The default value used is “self” which results in the form submission in the same window. For making the form result open in a new browser tab, the value should be set to “blank”.
 

html

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank">

  Username:<br>

  <input type="text" name="username">

  <br>

  Password:<br>

  <input type="password" name="password">

  <br><br>

  <input type="submit" value="Submit">

</form>

</body>

</html>

After clicking on the submit button, the result 
will open in a new browser tab.

Name Attribute in Html Forms : 
The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all.
 

html

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank">

  Username:<br>

  <input type="text">

  <br>

  Password:<br>

  <input type="password" name="password">

  <br><br>

  <input type="submit" value="Submit">

</form>

</body>

</html>

In the above code, after clicking the submit button, the form data will
be sent to a page called /test.php. The data sent would not include the
username input field data since the name attribute is omitted.

The Method Attribute :

It is used to specify the HTTP method used to send data while submitting the form.There are two kinds of HTTP Methods, which are GET and POST.
The GET Method –
 

html

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank" method="GET">

  Username:<br>

  <input type="text" name="username">

  <br>

  Password:<br>

  <input type="password" name="password">

  <br><br>

  <input type="submit" value="Submit">

</form>

</body>

</html>

In the GET method, after the submission of the form, the form values 
will be visible in the address bar of the new browser tab.

The Post Method –
 

html

<!DOCTYPE html>

<html>

<body>

<form action="/test.php" target="_blank" method="post">

  Username:<br>

  <input type="text" name="username">

  <br>

  Password:<br>

  <input type="password" name="password">

  <br><br>

  <input type="submit" value="Submit">

</form>

</body>

</html>

In the post method, after the submission of the form, the form values
will not be visible in the address bar of the new browser tab as it was
visible in the GET method.

Supported Browser:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.


How can we create a user input in HTML?

The <form> tag is used to get user input, by adding the form elements. Different types of form elements include text input, radio button input, submit button, etc. Let's learn about the <input> tag, which helps you to take user input using the type attribute.

Is used to create an HTML form for user input?

The <form> tag is used to create an HTML form for user input.

How do I create a simple HTML form?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to create the registration form. Step 2: Now, we have to place the cursor at that point where we want to create a form between the starting and closing of <body> tag in the Html document.

How do you create an input form?

Create an Access Input Form.
Select Create in the menu, and select Form Wizard..
Select the >> button to select all fields in the table..
Select the Next button to continue..
Choose the form layout that you'd like. ... .
Select the Next button to continue..