How to take user input using HTML forms?

Using HTML forms, you can easily take user input. 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. The attribute is used with the form elements such as text input, checkbox, radio, etc.


You can try to run the following code to take user input using HTML Forms:

Live Demo

<!DOCTYPE html>
         <title>HTML Forms</title>
      <p>Add your details:</p>
         Student Name:<br> <input type="text" name="name">
         Student Subject:<br> <input type="text" name="subject">
         Rank:<br> <input type="text" name="rank">

Above, you can see the following two attributes:

  • type
    Indicates the type of input control and for text input control it will be set to text
  • name
    Used to give a name to the control which is sent to the server to be recognized and get the value.