Forms

HTML Form

Creating HTML Forms

HTML form is <form>, collecting user input with action and method attributes.

Understanding HTML Forms

An HTML form is a section of a document that contains interactive controls, allowing users to submit data to a server. HTML forms are created using the <form> tag, which can contain various input elements, such as text fields, checkboxes, radio buttons, submit buttons, and more.

Key Attributes of the <form> Tag

The <form> tag has several important attributes that define its behavior:

  • action: The URL to which the form data will be sent.
  • method: The HTTP method to use when sending form data. Common methods are GET and POST.

Form Elements

HTML forms can contain various elements that users interact with:

  • Input fields: Used for text, numbers, passwords, etc.
  • Checkboxes and radio buttons: Allow users to select options.
  • Submit button: Sends the form data to the server.

Example: Creating a Simple Contact Form

Below is an example of a simple contact form with text inputs for a user's name and email, and a submit button:

In this example, the form uses the POST method to send data to the /contact URL. The required attribute ensures that the fields must be filled out before submitting.

Next
Input