HTML Form Attributes


Lesson 27 of 58

HTML forms have several attributes that control how they behave. These attributes tell the browser where to send the data, how to send it, and where to show the response.


The Action Attribute

The action attribute defines where the form data should be sent when the user clicks submit. Usually, this is a file on the server that processes the data.

If you omit the action attribute, the form data is sent to the current page itself.

Action Attribute Example
Tip: If you are just testing HTML forms locally and do not have a server, you can use action="#" which sends the data to the same page (nothing will happen, but the form structure works).

The Target Attribute

The target attribute specifies where to display the response after submitting the form. By default (_self), the response opens in the same tab.

Target Value Description
_blank Opens the response in a new tab or window
_self Opens the response in the same tab (default)
_parent Opens the response in the parent frame
_top Opens the response in the full body of the window
Target Attribute Example

The Method Attribute

The method attribute tells the browser how to send the form data. There are two main methods: GET and POST.

GET Method

With GET, the form data is appended to the URL. You can see it in the address bar. This is good for search forms or when you want users to bookmark the results.

GET Method Example

POST Method

With POST, the form data is sent in the background (in the HTTP request body). It does not appear in the URL. This is safer and has no size limits.

POST Method Example

GET vs POST: When to Use Which

GET POST
Data visibility Visible in URL Not visible in URL (in request body)
Security Not secure (do not use for passwords) More secure for sensitive data
Size limit Limited (2048 characters max) No size limit (can send large files)
Bookmarkable Yes, users can bookmark the result No, cannot bookmark POST requests
Best for Search forms, filters, queries Login forms, registrations, file uploads
Tip: Always use POST when the form contains sensitive or personal information like passwords, credit card numbers, or addresses. Use GET for search boxes where users might want to bookmark the results.

The Autocomplete Attribute

The autocomplete attribute tells the browser whether to remember and suggest previously entered values. This is helpful for forms that users fill out repeatedly.

Autocomplete Example

You can also turn autocomplete off for the entire form or for specific fields:

Autocomplete Off
<form action="/action_page.php" method="post" autocomplete="off">
Note: Some browsers may ignore autocomplete for certain sensitive fields (like passwords) for security reasons.

The Novalidate Attribute

The novalidate attribute tells the browser NOT to validate the form data before submitting. This means the browser will not check if required fields are filled or if emails are correctly formatted.

This can be useful when you want to use your own custom validation with JavaScript.

Novalidate Example
Warning: Turning off browser validation does NOT mean you can skip server-side validation. Always validate data on the server for security!

Complete Form Attributes Example

Here is a complete form using multiple attributes together:

All Form Attributes Together

Quick Summary

  • action – Where to send the form data (usually a server-side script)
  • target – Where to display the response (_self or _blank)
  • method – How to send data (get or post)
  • autocomplete – Whether browser should suggest previous values
  • novalidate – Turn off browser validation
  • Use POST for sensitive data and GET for search forms
  • Always validate data on the server, even if you use novalidate

What Just Happened? Let Me Explain

  • The action attribute points to a backend script (like /action_page.php). That script receives the data and processes it (saves to database, sends email, etc.).
  • Using target="_blank" is nice when you want users to keep the original form open while seeing the result in a new tab.
  • GET puts data in the URL. You can see it. POST hides it. That is why POST is for passwords.
  • Autocomplete saves users time by remembering what they typed before. Turn it off only for very sensitive fields.
  • The novalidate attribute is useful when you want to build your own validation with JavaScript. But always validate on the server too.
Tip: When building real websites, always use method="post" for login, registration, and contact forms. Use method="get" for search boxes and filters where users might share or bookmark the URL.

HTML Form Attributes Reference

Here are all the form attributes we covered in this chapter:

Attribute Description
action Specifies where to send the form data
target Specifies where to display the response
method Specifies HTTP method (get or post)
autocomplete Whether form should have autocomplete on/off
novalidate Turns off browser validation when present

Lesson 27 of 58