Tutorials HTML Form Attributes
Ch 12 / 40
Chapter 12 Beginner 8 min read HTML

HTML Form Attributes

The <form> element has a rich set of attributes that control where data goes, how it travels, whether the browser validates it, and much more. In this chapter you'll master every <form> tag attribute in depth — and learn how individual elements can override form-level settings using formaction, formmethod, and other per-element overrides.

What you'll learn
All <form> tag attributes — action, method, enctype, target
GET vs POST — when to use each and why
The three enctype values and when each is needed
autocomplete and novalidate on forms
Per-element overrides — formaction, formmethod, formenctype
The form attribute — linking inputs outside the form tag

The <form> Tag — Full Attribute Overview

The <form> element acts as the controller for all data collection. Its attributes define the entire submission pipeline. Here is what a fully configured form tag looks like:

HTML — Fully configured form tag
<form
  action="/submit"
  method="POST"
  enctype="multipart/form-data"
  target="_blank"
  autocomplete="on"
  novalidate
  accept-charset="UTF-8"
  rel="noreferrer"
  id="enroll-form"
  name="enrollmentForm"
>
  <!-- form elements go here -->
</form>

All <form> Attributes — In Depth

Here is every <form> attribute explained in detail with valid values:

action Submission URL Optional
Specifies the URL where form data is sent when the user submits. If omitted, the form submits to the current page URL. Can be absolute or relative. The server at this URL receives and processes the data.
action="/submit"
action="https://api.example.com/form"
action="../process.php"
method HTTP Method Optional
Defines how data is sent to the server. GET appends data to the URL (visible, bookmarkable). POST sends data in the request body (hidden, secure). Default is GET.
method="GET" ← default, for search
method="POST" ← secure, for data
enctype Encoding Type Optional
Controls how form data is encoded before sending. Only applies with method="POST". Must be set to multipart/form-data for file uploads to work correctly.
enctype="application/x-www-form-urlencoded"
enctype="multipart/form-data"
enctype="text/plain"
target Response Target Optional
Specifies where to display the server response after submission. Works like the target on links. Default is _self — shows response in the same tab.
target="_self" ← same tab (default)
target="_blank" ← new tab
target="_parent" ← parent frame
target="_top" ← full window
autocomplete Autofill Control Optional
Controls whether the browser can autofill fields in the form. When set on the <form> element, it sets the default for all child inputs — which can individually override it.
autocomplete="on" ← allow autofill (default)
autocomplete="off" ← disable autofill
novalidate Disable Validation Optional
A boolean attribute (no value needed). When present, it completely disables the browser's built-in HTML5 validation — the form will submit even if fields contain invalid data or are empty. Use when you handle validation entirely with JavaScript.
<form novalidate>
← disables all HTML5 validation
accept-charset Character Encoding Optional
Specifies the character encoding used when submitting the form. The default is UTF-8 in modern browsers. You almost never need to set this explicitly unless your server requires a specific encoding.
accept-charset="UTF-8" ← default
accept-charset="ISO-8859-1"
rel Link Relationship Optional
Describes the relationship between the form page and the action URL. Works similarly to rel on links. Mostly used for security when target="_blank" is set on the form.
rel="noreferrer"
rel="noopener"
rel="external"

GET vs POST — Which to Use and When

Choosing the right HTTP method is one of the most important form decisions. Here is a detailed comparison:

GET method="GET"
Data is appended to the URL as query string — e.g. /search?q=html&page=1
Results can be bookmarked and shared by copying the URL
Browser can cache GET requests — faster repeat searches
Data is visible in the URL — never use for passwords or sensitive data
URL length is limited (~2000 chars) — cannot send large amounts of data
Cannot upload files — no binary data support
POST method="POST"
Data is sent in the HTTP request body — invisible in the URL
Suitable for passwords, personal data, and any sensitive information
No size limit on data — can send large payloads
Required for file uploads with enctype="multipart/form-data"
Cannot be bookmarked — submitting again shows "Resend data?" browser warning
Not cached by browsers — every submit hits the server
Simple Rule
Use GET for search boxes, filters, and any form that retrieves data. Use POST for login, registration, payment, contact forms, and any form that sends or changes data on the server. When in doubt, use POST.

The enctype Attribute — Three Values Explained

The enctype attribute tells the browser how to encode the form data before sending it to the server. It only applies when method="POST". There are exactly three valid values:

enctype Value When to Use What It Does
application/x-www-form-urlencoded Default — use for all standard forms without file uploads URL-encodes all characters — spaces become +, special chars become %XX hex codes. Compact and efficient for text data.
multipart/form-data Required for any form containing <input type="file"> Splits the request into multiple parts — one per field. Each part has its own content type header, allowing binary file data to be transmitted correctly alongside text fields.
text/plain Debugging only — do not use in production Sends data as plain text with no encoding. Useful only for reading raw form data during development. Not suitable for actual form processing — no encoding means special characters may break parsing.
HTML — File upload form (requires multipart/form-data)
<!-- File upload REQUIRES both method="POST" and enctype="multipart/form-data" -->
<form
  action="/upload-avatar"
  method="POST"
  enctype="multipart/form-data"
>
  <label for="avatar">Upload Profile Photo</label>
  <input
    type="file"
    id="avatar"
    name="avatar"
    accept="image/*"
    required
  >
  <button type="submit">Upload</button>
</form>
File Upload Rule
A form with <input type="file"> must have both method="POST" and enctype="multipart/form-data". Without either, the file is not transmitted — only the filename is sent, which is useless to the server.

target, autocomplete & novalidate

Three more important form attributes used frequently in real projects:

target="_blank"
Opens the server response in a new browser tab instead of the current page. Useful when submitting to a third-party payment gateway or print preview that should open separately. When used on a form, also add rel="noreferrer" for security.
autocomplete="off"
Disables browser autofill for all fields in the form. Useful for sensitive forms like one-time passwords, security questions, or credit card data where autofill would be inappropriate. Individual inputs can override with autocomplete="on".
novalidate
Completely disables the browser's built-in HTML5 validation on every field in the form. The form will submit regardless of required fields or invalid formats. Use when you want to implement custom JavaScript validation instead of relying on native browser validation bubbles.
HTML — target, autocomplete, novalidate examples
<!-- Response opens in new tab -->
<form action="/payment" method="POST"
      target="_blank" rel="noreferrer">
  ...
</form>

<!-- Disable autofill for sensitive form -->
<form action="/verify" method="POST"
      autocomplete="off">
  <input type="text" name="otp" placeholder="Enter OTP">
</form>

<!-- Disable browser validation — handle with JS -->
<form action="/register" method="POST"
      novalidate id="regForm">
  <!-- JS validates and shows custom error UI -->
</form>

Per-element Form Attribute Overrides

HTML5 allows individual <button>, <input type="submit">, and <input type="image"> elements to override the form-level settings on a per-submission basis. This is extremely useful when one form needs multiple submit buttons that send data to different endpoints or with different methods.

formaction
Overrides action
Sends the form to a different URL when this specific button is clicked — overrides the action on the <form> tag. Perfect for "Save Draft" vs "Publish" buttons in the same form.
formmethod
Overrides method
Changes the HTTP method for this specific submission — overrides the form's method. Allows one button to use GET and another to use POST from the same form.
formenctype
Overrides enctype
Overrides the form's enctype for this button's submission. Useful when one button submits normally and another triggers a file upload.
formtarget
Overrides target
Overrides where the server response is displayed for this specific button. One button can open the response in the current tab, another in a new tab — from the same form.
formnovalidate
Overrides novalidate
Disables validation for this button's click only. Classic use case: a "Save Draft" button that bypasses required field validation, while the main "Submit" button still validates.
form
Links to a <form id>
Allows an input or button placed outside a <form> tag to be associated with a form. The value must match the form's id. Enables flexible layouts where form fields and buttons are in different DOM locations.
HTML — formaction, formnovalidate, form attribute in action
<form
  id="article-form"
  action="/publish"
  method="POST"
>
  <label for="title">Article Title</label>
  <input type="text" id="title" name="title" required>

  <label for="body">Content</label>
  <textarea id="body" name="body" required></textarea>

  <!-- Save Draft — sends to /draft, skips validation -->
  <button
    type="submit"
    formaction="/save-draft"
    formnovalidate
  >Save Draft</button>

  <!-- Publish — sends to /publish, full validation, new tab -->
  <button
    type="submit"
    formaction="/publish"
    formtarget="_blank"
  >Publish Article</button>
</form>

<!-- Input OUTSIDE the form — linked via form="article-form" -->
<input
  type="text"
  name="tags"
  form="article-form"
  placeholder="Add tags..."
>
Practical Use Case
The form attribute is invaluable for complex page layouts where a submit button lives in a fixed footer or sidebar, far from the <form> tag in the HTML. Instead of restructuring the entire DOM, simply add form="formId" on the button and it behaves as if it were inside the form.

Common Mistakes — Do's & Don'ts

These are the most frequent form attribute mistakes beginners make:

Do — Correct
<!-- POST for sensitive data -->
<form
  action="/login"
  method="POST"
  autocomplete="off"
>

<!-- multipart for file uploads -->
<form
  action="/upload"
  method="POST"
  enctype="multipart/form-data"
>
Don't — Wrong
<!-- GET for login — password in URL! -->
<form
  action="/login"
  method="GET"
>

<!-- File upload without multipart -->
<form
  action="/upload"
  method="POST"
>
<!-- file won't be sent correctly -->

Complete Example — Multi-action Article Editor

A realistic example using formaction, formnovalidate, formtarget, and the form attribute together:

HTML — Full form attributes demo
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Article Editor</title>
</head>
<body>

  <!-- Main form — publishes to /publish -->
  <form
    id="editor"
    action="/publish"
    method="POST"
    enctype="multipart/form-data"
    autocomplete="on"
  >

    <label for="title">Title *</label>
    <input type="text" id="title"
           name="title" required>

    <label for="cover">Cover Image</label>
    <input type="file" id="cover"
           name="cover" accept="image/*">

    <label for="body">Content *</label>
    <textarea id="body" name="body" required></textarea>

    <!-- Save Draft: skips validation, saves to /draft -->
    <button type="submit"
            formaction="/save-draft"
            formnovalidate>
      Save Draft
    </button>

    <!-- Publish: full validation, opens preview in new tab -->
    <button type="submit"
            formtarget="_blank">
      Publish
    </button>

  </form>

  <!-- Tags input placed OUTSIDE the form — linked via form="editor" -->
  <input
    type="text"
    name="tags"
    form="editor"
    placeholder="Tags (comma-separated)"
  >

</body>
</html>

Try It Yourself

Edit the form below and click Open in Editor to experiment with form attributes live. Try changing method, target, and novalidate.

Live Editor
✎ Editor
👁 Preview
Try This
Click Save Draft — it submits even though the required fields are empty, because formnovalidate is set. Then try Publish without filling in fields — it triggers browser validation because formnovalidate is not set on that button.
Free Resource
HTML5 Cheat Sheet — All Tags & Attributes
One printable PDF covering all form attributes, enctype values, GET vs POST comparison, and all per-element overrides.
Download PDF
Featured Course — Enroll Now
Modern Web Development With AI
Master HTML, CSS, JavaScript, React, and Node.js in one industry-ready curriculum with real projects and placement support.
120+
Chapters
40 hrs
Content
10
Projects
4.9 ⭐
Rating
HTML5 CSS3 JavaScript React.js Node.js MongoDB AI Tools

Quick Check — Chapter 12

Expand each question to check your understanding before moving on to the multiple choice quiz below.

Questions & Answers
When action is omitted, the form submits data to the current page's URL — the same page the user is already on. This is useful for single-page apps or PHP pages that both display and process the form. The browser reloads the current URL with the form data appended (for GET) or in the request body (for POST). It is perfectly valid — just be sure your server-side code is prepared to handle the submission on that URL.
method="POST" is required because GET appends data to the URL and has a character limit — it cannot handle binary file data. enctype="multipart/form-data" is required because the default encoding (application/x-www-form-urlencoded) URL-encodes everything as text — binary file content gets corrupted in this process. multipart/form-data splits the request into separate parts, each with its own content type, allowing binary files to be transmitted correctly alongside text fields. Without both, the file simply does not arrive at the server.
novalidate is a boolean attribute that completely disables the browser's built-in HTML5 validation. Without it, clicking submit triggers the browser to check required, pattern, type constraints, etc. — and show its default error bubbles. With novalidate, the form submits regardless of field values. Use it when you want to implement custom JavaScript validation with your own error UI, progressive validation on blur, or a multi-step form where partial submission is intentional (e.g. "Save Draft" scenarios).
action is set on the <form> tag and defines the default submission URL for all buttons. formaction is set on a specific <button type="submit"> or <input type="submit"> and overrides the form's action only when that button is clicked. The main use case is a form with multiple submit buttons pointing to different endpoints — for example an article editor with "Save Draft" (sends to /save-draft) and "Publish" (sends to /publish) buttons in the same form.
The form attribute allows an input (or button) placed outside a <form> tag to be associated with a specific form. The attribute value must match the id of the target form. When the form is submitted, all fields with a matching form attribute are included in the submission — even though they are not physically nested inside the form's HTML tags. This is extremely useful for complex page layouts where the submit button lives in a fixed header or sidebar far from the form content.
Set autocomplete="off" on a form when autofill would be inappropriate or potentially harmful. Classic examples: OTP (one-time password) fields — the user must type fresh each time; bank security questions — answers should not be saved; admin panels with sensitive actions — preventing accidental autofill; forms where users log in as different people (shared computers). Setting it on the <form> disables autofill for all child inputs by default, but individual inputs can re-enable it with autocomplete="on". Note that some browsers may still override this for password fields as a security feature.
Multiple Choice Questions
MCQ 1 of 4
Which enctype value is required when a form includes a file upload input?
MCQ 2 of 4
Which attribute on a submit button overrides the form's action URL for that specific button only?
MCQ 3 of 4
Which form method should you use for a login form that submits a username and password?
MCQ 4 of 4
Which attribute allows an input placed outside a <form> tag to be submitted with that form?
Chapter Summary
  • action = the URL where data is sent (defaults to current page). method = GET (visible, bookmarkable) or POST (hidden, secure — use for sensitive data).
  • enctype has three values: application/x-www-form-urlencoded (default), multipart/form-data (required for file uploads), text/plain (debug only).
  • target controls where the response is shown — _self (default, same tab), _blank (new tab).
  • autocomplete="off" disables browser autofill for all fields. novalidate disables all built-in HTML5 validation.
  • Per-element overrides: formaction, formmethod, formenctype, formtarget, formnovalidate — set on individual submit buttons to override form-level attributes for that button only.
  • The form attribute on any input or button links it to a form by id — even if the element lives outside the <form> tag in the HTML.
~8 min read
Beginner level
Chapter 12 of 40

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
If this tutorial helped you, a 5-star Google review means a lot. It helps other learners discover our free content and motivates us to keep improving.
500+ Reviews (Target)
Write a Google Review
Join WhatsApp Channel