Creating Forms

HTML forms are used to collect user input. They can be used to collect contact information, user preferences, or any other type of data.

The <form> element is used to define a form. The <input> element is used to define the input fields in a form. The <label> element is used to label the input fields in a form.

Here is an example of a simple form:

<form action="">
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  <br>
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
  <br>
  <input type="submit" value="Submit">
</form>

This form defines two input fields: a text field for the user’s name and an email field for the user’s email address. The action attribute of the <form> element specifies the URL of the page that will be called when the form is submitted.

Task

Create an empty HTML form with an action attribute after the Contact Me heading. Do not give any value to the action attribute. Run the code to see the results and experiment with the code to get used to it.

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT