learn2kode.in

HTML Form Attributes

Form attributes define how a form behaves when the user submits the data. These attributes are applied to the <form> tag.

Example

<form action="submit.php" method="post">

Below are the most commonly used form attributes.

1. Action Attribute

Defines the URL where the form data will be sent.

<form action="submit.php">

If omitted, the form submits to the same page.

2. Method Attribute

Specifies how form data is sent.

Method Usage
GET Data visible in URL
POST Data sent securely inside request body

Example

<form action="register.php" method="post">

3. Target Attribute

Defines where to open the response.

Value Meaning
_self Opens in the same tab (default)
_blank Opens in a new tab
_parent Opens in parent frame
_top Opens full window

Example

<form action="search.php" target="_blank">

4. Autocomplete Attribute

Controls browser autofill.

Value Meaning
on Enable autofill
off Disable autofill

5. Enctype Attribute

Defines how form data is encoded when sent to the server.

 Required for file uploads.

Value Use Case
application/x-www-form-urlencoded Default
multipart/form-data File uploads
text/plain Debugging text format

Example (file upload):

<form method="post" enctype="multipart/form-data">

6. Novalidate Attribute

Disables built-in browser validation.

7. Name Attribute

Gives a name to the form (useful in JavaScript).

HTML Form Attributes

<table border="1" cellpadding="8" cellspacing="0">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>

  <tr>
    <td><code>action</code></td>
    <td>URL where the form sends data</td>
  </tr>

  <tr>
    <td><code>method</code></td>
    <td>HTTP method (<code>GET</code> or <code>POST</code>)</td>
  </tr>

  <tr>
    <td><code>target</code></td>
    <td>Where to open the response (<code>_self</code>, <code>_blank</code>)</td>
  </tr>

  <tr>
    <td><code>autocomplete</code></td>
    <td>Enables or disables autofill</td>
  </tr>

  <tr>
    <td><code>enctype</code></td>
    <td>Encoding type for form data (required for file uploads)</td>
  </tr>

  <tr>
    <td><code>novalidate</code></td>
    <td>Disables browser validation</td>
  </tr>

  <tr>
    <td><code>name</code></td>
    <td>Specifies form name</td>
  </tr>
</table>

Output

Attribute Description
action URL where the form sends data
method HTTP method (GET or POST)
target Where to open the response (_self, _blank)
autocomplete Enables or disables autofill
enctype Encoding type for form data (required for file uploads)
novalidate Disables browser validation
name Specifies form name