HTML Form Attributes
The <form> element accepts attributes that control how and where the data is sent.
Form attributes
| Attribute | Purpose | Common values |
|---|---|---|
action | URL to send the form to. | Any path or full URL. |
method | HTTP method. | get, post |
enctype | How form data is encoded. | application/x-www-form-urlencoded (default), multipart/form-data (for file uploads), text/plain |
target | Where the response opens. | _self, _blank |
autocomplete | Whether the browser may autofill. | on, off |
novalidate | Skip the browser's built-in validation. | (no value) |
name | Identifier — useful when many forms share a page. | Any string. |
GET vs POST in one sentence
- GET: data is in the URL — fine for searches, bookmarks, and idempotent reads.
- POST: data is in the request body — required for anything that creates, updates, or contains sensitive information.
Note: File uploads must use
method="post" and enctype="multipart/form-data" — otherwise the file content never reaches the server.Example
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Attributes</title>
</head>
<body>
<h1>HTML Form Attributes</h1>
<p>This is a demo page for the "HTML Form Attributes" lesson.</p>
</body>
</html>
Try it Yourself »
Exercise
Send this form using the HTTP verb that keeps data out of the URL.
<form action="/login"
="post">…</form>
Six letters. The HTTP-related form attribute.
Discussion
Loading…