HTML - <form> tag in HTML

The <form> tag in HTML is used to create an input form that collects user data and sends it to a server for processing.

Here are 6 common attributes of the <form> tag with examples:

  1. action
    Specifies the URL where the form data will be sent after submission.
    Example:
    <form action="/submit-form">

  2. method
    Specifies the HTTP method to use when sending form data. Common values are get and post.
    Example:
    <form method="post">

  3. enctype
    Specifies how the form data should be encoded when submitted.
    Common values:

  • application/x-www-form-urlencoded (default)

  • multipart/form-data (used for file uploads)
    Example:
    <form enctype="multipart/form-data">

  1. target
    Specifies where to display the response after form submission.
    Common values: _self, _blank, _parent, _top
    Example:
    <form target="_blank">

  2. autocomplete
    Enables or disables browser autocomplete for form fields.
    Values: on or off
    Example:
    <form autocomplete="off">

  3. novalidate
    Tells the browser not to validate the form before submission.
    Example:
    <form novalidate>

Example combining attributes:

 

<form action="/submit" method="post" enctype="multipart/form-data" target="_self" autocomplete="on" novalidate>
  <!-- form elements go here -->
</form>