← Back to HTML Course | Chapter 5: Forms | Lesson 2 of 7

HTML Form Attributes

Imagine filling out a paper feedback form at a local restaurant. Once you are finished, you do not just leave the paper sitting on your table; you look for the feedback box on the wall to drop it in. Form attributes are those delivery instructions. They do not change what input fields are displayed on your page, but they tell the browser exactly where to send your data (the server endpoint), how to package it (GET or POST), and how to display the response. Configuring these attributes is essential for keeping your user data secure and your forms functioning correctly.

The action Attribute

The action attribute defines the server URL or endpoint where the form data will be sent when the user clicks the submit button.

Note: If you leave the action attribute empty, the browser will submit the data straight to the current page URL.

Warning: Make sure your action URL is completely correct and secure, or your form submissions will fail.

Example: The action Attribute

markup
<form action="/submit-form">
  <input type="text" name="query">
</form>

The method Attribute

The method attribute defines the HTTP protocol method used to transmit your form data. You can choose between the GET method (which appends data to the URL path) and the POST method (which hides the data inside the request body).

Note: Use the GET method for search queries, and the POST method for sensitive information like passwords or file uploads.

Warning: Never use the GET method to transmit passwords or personal data, as they will be displayed openly in the browser address bar.

Example: The method Attribute

markup
<form action="/search" method="get">
  <input type="text" name="q">
</form>

The target Attribute

The target attribute tells the browser where to display the response page after the form is submitted. It works exactly like the target attribute on standard links, allowing you to load response pages in the current window or a new tab.

Note: Set target="_blank" when you want to keep users on your current tool page after they submit feedback.

Warning: Do not overuse target="_blank" as opening endless tabs can clutter your user's desktop browser.

Example: The target Attribute

markup
<form action="/feedback" method="post" target="_blank">
  <input type="text" name="comment">
</form>

The autocomplete Attribute

The autocomplete attribute tells the browser if it can automatically fill in form fields based on the user's past entries. You can toggle this setting on or off for the entire form or for specific input fields.

Note: Keep autocomplete enabled on registration forms to save your users from typing repetitive details.

Warning: Disable autocomplete on sensitive fields like bank accounts or security codes to protect user privacy on shared computers.

Example: The autocomplete Attribute

markup
<form autocomplete="on">
  <input type="text" name="username">
</form>

The novalidate Attribute

By default, browsers perform basic validation checks on form fields (like ensuring email fields contain an '@' symbol) before submitting. The novalidate attribute disables these native browser checks, letting you handle validation using custom JavaScript instead.

Note: Use the novalidate attribute when you want to design custom, styled error messages using JavaScript.

Warning: If you disable browser validation using novalidate, you must write custom script validation to prevent users from submitting blank forms.

Example: The novalidate Attribute

markup
<form action="/submit" novalidate>
  <input type="email" name="email" required>
</form>
Common Mistakes
  1. Using the public GET method to transmit sensitive user passwords or payment details.
  2. Misspelling your server endpoint URLs inside the action attribute, causing form submissions to fail.
  3. Disabling browser validation using the novalidate attribute without writing custom scripts to verify user inputs.
Chapter Summary
  • The action attribute specifies the destination URL where your form data will be sent.
  • The method attribute defines how data is transmitted: publicly in the URL (GET) or securely inside the request body (POST).
  • Control browser autofill features using autocomplete, and toggle native browser validation checks using novalidate.
Browser Support

Standard HTML form attributes are supported natively by all web browsers.

🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.