Input Form Attributes in HTML
? Input Form Attributes in HTML
In HTML, the <form> element has attributes that control how the form behaves when submitting data, while <input> elements inside the form have their own specific attributes. Here, we'll focus on the form-level attributes related to inputs and form submission.
Common <form> Attributes
| Attribute | Description | Example |
|---|---|---|
action | URL where the form data is sent after submission | <form action="/submit-form"> |
method | HTTP method used to send the form data (GET or POST) | <form method="POST"> |
enctype | Encoding type for form data (important for file uploads) | <form enctype="multipart/form-data"> |
name | Name of the form (used in scripts) | <form name="userForm"> |
target | Where to display the response (_self, _blank, etc.) | <form target="_blank"> |
autocomplete | Enable or disable browser autocomplete for the form | <form autocomplete="off"> |
novalidate | Disables browser’s automatic validation | <form novalidate> |
Brief Explanation
action: Specifies the URL of the server-side script that will process the form data.method: CommonlyGET(data appended to URL) orPOST(data sent in request body).enctype: Use"multipart/form-data"for forms that upload files. Default is"application/x-www-form-urlencoded".autocomplete: Helps users by autofilling saved info. Use"off"to disable.novalidate: Prevents automatic validation; useful if you want to handle validation with JavaScript.
Example Form Using These Attributes
<form action="/submit" method="POST" enctype="multipart/form-data" autocomplete="on" novalidate> <input type="text" name="username" required placeholder="Username"> <input type="file" name="profilePic"> <button type="submit">Submit</button></form>Want me to explain how to use these form attributes with input validation or file uploads?