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.
<form> tag attributes
— action, method, enctype, targetenctype values and
when each is neededautocomplete and novalidate on formsformaction, formmethod, formenctypeform attribute — linking
inputs outside the form tagThe <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:
<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="https://api.example.com/form"
action="../process.php"
GET appends data to the URL (visible, bookmarkable). POST sends data in the request body (hidden, secure). Default is GET.method="POST" ← secure, for data
method="POST". Must be set to multipart/form-data for file uploads to work correctly.
enctype="multipart/form-data"
enctype="text/plain"
target on links. Default is _self — shows response in the same tab.target="_blank" ← new tab
target="_parent" ← parent frame
target="_top" ← full window
<form> element, it sets the default for all child
inputs — which can individually override it.autocomplete="off" ← disable autofill
← disables all HTML5 validation
UTF-8 in modern browsers. You almost never need to set
this explicitly unless your server requires a specific encoding.accept-charset="ISO-8859-1"
rel on links. Mostly used for security when target="_blank" is set on the form.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:
/search?q=html&page=1
enctype="multipart/form-data"
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. |
<!-- 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>
<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:
rel="noreferrer" for
security.autocomplete="on".<!-- 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.
actionaction on the <form>
tag. Perfect for "Save Draft" vs "Publish" buttons in the same form.methodmethod. Allows one button to use GET and another to use POST from the
same form.enctypeenctype for this button's
submission. Useful when one button submits normally and another triggers a file upload.targetnovalidate<form id><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.<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..."
>
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:
<!-- POST for sensitive data -->
<form
action="/login"
method="POST"
autocomplete="off"
>
<!-- multipart for file uploads -->
<form
action="/upload"
method="POST"
enctype="multipart/form-data"
>
<!-- 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:
<!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.
formnovalidate is set. Then try Publish without filling in
fields — it triggers browser validation because formnovalidate is not
set on that button.
Quick Check — Chapter 12
Expand each question to check your understanding before moving on to the multiple choice quiz below.
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.
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.
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.
enctype value is required when a form
includes a file upload input?action URL for that specific button only?<form> tag to be submitted with that form?action= the URL where data is sent (defaults to current page).method= GET (visible, bookmarkable) or POST (hidden, secure — use for sensitive data).enctypehas three values:application/x-www-form-urlencoded(default),multipart/form-data(required for file uploads),text/plain(debug only).targetcontrols where the response is shown —_self(default, same tab),_blank(new tab).autocomplete="off"disables browser autofill for all fields.novalidatedisables 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
formattribute on any input or button links it to a form byid— even if the element lives outside the<form>tag in the HTML.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions, and stay updated with new tutorials.