HTML Forms

HTML forms are used to collect information from users. Forms allow users to enter data such as names, email addresses, passwords, phone numbers, feedback, and other details. The collected data can be sent to a server for processing. The <form> tag is used to create a form, and it contains different input controls.


Form Elements

HTML provides different form elements to collect various types of user input.

  • <form> - Creates a form.
  • <label> - Defines a label for an input field.
  • <input> - Creates an input box.
  • <textarea> - Creates a multi-line text area.
  • <select> - Creates a drop-down list.
  • <option> - Defines options inside a select box.
  • <button> - Creates a clickable button.

Form Syntax


<form>


    <label>Name</label>

    <input type="text">



    <label>Password</label>

    <input type="password">



    <button>Submit</button>


</form>



Example


<form>


    <label>Name:</label>

    <input type="text">



    <br><br>



    <label>Email:</label>

    <input type="email">



    <br><br>



    <label>Password:</label>

    <input type="password">



    <br><br>



    <button>Submit</button>



</form>


Output











Best Practices

  • Use labels for every input field.
  • Choose correct input types like text, email, and password.
  • Keep forms simple and user friendly.
  • Group related fields together.
  • Use meaningful button names like Submit or Register.
  • Validate user input before processing the form.