HTML - Form Tag Attributes

The HTML <form> element is used to create a form on a web page, allowing users to input and submit data. The <form> element supports several attributes that provide additional functionality and control over the form's behavior. Here are the details of some commonly used form attributes:

action:

  • Specifies the URL or script where the form data should be submitted.
<form action="/submit-form" method="POST">

method:

  • Defines the HTTP method to be used when submitting the form data.
  • Common values are "GET" and "POST".
  • "GET" appends the form data to the URL as query parameters, while "POST" sends the data in the body of the HTTP request.
<form action="/submit-form" method="POST">

target:

  • Specifies where the response from the form submission should be displayed.
  • Common values include "_self" (default, same frame or window), "_blank" (new window), "_parent" (parent frame), or a named frame/window.
<form action="/submit-form" method="POST" target="_blank">

enctype:

  • Defines the encoding type used when submitting the form data to the server.
  • Common values are "application/x-www-form-urlencoded" (default, URL encoding) and "multipart/form-data" (used when uploading files).
<form action="/submit-form" method="POST" enctype="multipart/form-data">

autocomplete:

  • Specifies whether browser autofill should be enabled for the form fields.
  • Common values are "on" (default, enables autofill) and "off" (disables autofill).
<form action="/submit-form" method="POST" autocomplete="off">

novalidate:

  • Indicates that the form should not be validated when submitted.
  • Useful when implementing custom form validation using JavaScript.
<form action="/submit-form" method="POST" novalidate>

These are just a few of the attributes available for the <form> element. There are additional attributes like accept-charset, onsubmit, onreset, etc., which provide further control and functionality.

Remember to choose the appropriate attributes based on your specific requirements and the behavior you want to achieve with your form.