Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. HTML Tag Dictionary
  3. <form>

<form>

The <form> element is a container for user input that submits data to a server. You specify the destination URL and submission method using attributes.

Syntax

<form action="destination-url" method="post">
  <!-- Place form controls here -->
  <input type="text" name="username">
  <button type="submit">Submit</button>
</form>

Attributes

AttributeDescription
actionSpecifies the URL to which the form data is submitted. If omitted, the data is sent to the current page's URL.
methodSpecifies the submission method. Use get (appends data to the URL) or post (includes data in the request body).
enctypeSpecifies the encoding type for the submitted data. Use multipart/form-data when the form includes file uploads.
novalidateWhen present, disables the browser's built-in form validation.
autocompleteEnables (on) or disables (off) autocomplete for the entire form.
targetSpecifies the browsing context in which to display the response. Use _blank to open it in a new tab.

Sample Code

<!-- Basic contact form -->
<form action="/contact.php" method="post" autocomplete="on">

  <div>
    <label for="name">Name (required)</label>
    <input type="text" id="name" name="name" required>
  </div>

  <div>
    <label for="email">Email address (required)</label>
    <input type="email" id="email" name="email" required>
  </div>

  <div>
    <label for="message">Message</label>
    <textarea id="message" name="message" rows="5"></textarea>
  </div>

  <button type="submit">Send</button>

</form>

<!-- File upload form -->
<form action="/upload.php" method="post" enctype="multipart/form-data">
  <input type="file" name="file">
  <button type="submit">Upload</button>
</form>

Output

A text field for name, an email field, a textarea, and a submit button are displayed. Clicking "Send" validates the input, and if there are no errors, the data is submitted via POST to /contact.php.

Notes

Use method="get" when you want the data to appear in the URL, such as for search forms. Use method="post" when submitting sensitive data such as passwords or personal information that should not be visible in the URL. Always use method="post" for forms that handle passwords or personal information, and make sure the page is served over HTTPS.

The default value of the enctype attribute is application/x-www-form-urlencoded, which works fine for ordinary text data. If the form includes a file upload, you must specify multipart/form-data. Without it, the file will not be submitted correctly.

For input controls you can place inside a form (such as text fields), see input (text-based).

Browser Compatibility

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
Supported in all versions
Safari Safari
18+
2 or earlier ×
Edge Edge
80+
11 or earlier ×
IE IE
11 or earlier ×
Opera Opera
48+
14 or earlier ×
iOS Safari iOS Safari
18+
1 or earlier ×
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .