Go Back

HTML Form Attributes Explained | Form Attributes in HTML ...

3/14/2024
All Articles

#HTML Form Attributes Explained | Form Attributes in HTML ...

HTML Form Attributes Explained | Form Attributes in HTML ...

How to Create HTML Forms – Tutorial with Examples

In HTML, the <form> tag is used to provide a container for different form elements, like buttons, radio buttons, checkboxes, and input fields. It encapsulates these components and establishes the form's structure.

<form action="URL" method="GET/POST" enctype="multipart/form-data">
    <!-- other Form elements /input element-->
</form>

 

Important point of form tag :

 

  1. action: It is Specifies the URL which the form data is submitted for processing in server or backend. This can be a relative or absolute URL.
  2. method: Defines the HTTPs method used to submit the form data. It can be either GET or POST.
  3. GET: Appends form data to the URL as query parameters.
  4. POST: Sends form data in the request body.
  5. enctype: Specifies the encoding type for form data when submitting files. It is used when the form includes <input type="file"> elements.
  6. enctype="application/x-www-form-urlencoded" (default): Form data is URL-encoded.
  7. enctype="multipart/form-data": Used when uploading files.
  8. enctype="text/plain": Form data is submitted as plain text.

Below is example of form attribute and element:

<form action="/submit.js" method="POST" enctype="multipart/form-data">
    <!-- Form elements -->
    <input type="text" id="username" name="username"><br><br>
    <input type="password" id="password" name="password"><br><br>
    <input type="email" id="email" name="email"><br><br>
    <input type="file" id="file" name="file"><br><br>
    <input type="submit" value="Submit">
</form>

 

Conclusion

In This article , we are multiple use  case of form  tag .Building interactive web apps that gather and handle user data requires an understanding of the form tag and its properties.

 

Article