Form Attributes

AttributeValueDescription
accept-charsetcharacter_setSpecifies the character encodings that are to be used for the form submission
actionURLSpecifies where to send the form-data when a form is submitted
autocompleteon
off
Specifies whether a form should have autocomplete on or off
enctypeapplication/x-www-form-urlencoded
multipart/form-data
text/plain
Specifies how the form-data should be encoded when submitting it to the server (only for method="post")
methodget
post
Specifies the HTTP method to use when sending form-data
nametextSpecifies the name of a form
novalidatenovalidateSpecifies that the form should not be validated when submitted
relexternal
help
license
next
nofollow
noopener
noreferrer
opener
prev
search
Specifies the relationship between a linked resource and the current document
target_blank
_self
_parent
_top
Specifies where to display the response that is received after submitting the form

HTML <form> accept-charset Attribute

Definition and Usage

The accept-charset attribute specifies the character encodings that are to be used for the form submission.

Example

<form action="/action_page.php" accept-charset="utf-8">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
</form>

Syntax

<form accept-charset="character_set">

Attribute Values

ValueDescription
character_set A space-separated list of one or more character encodings that are to be used for the form submission.

Common values:

  • UTF-8 - Character encoding for Unicode
  • ISO-8859-1 - Character encoding for the Latin alphabet

In theory, any character encoding can be used, but no browser understands all of them. The more widely a character encoding is used, the better the chance that a browser will understand it.

To view all available character encodings, go to our Character sets reference.

HTML <form> action Attribute

Example -

<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>

Definition and Usage

The action attribute specifies where to send the form-data when a form is submitted.

Syntax

<form action="URL">

Attribute Values

Value Description
URL Where to send the form-data when the form is submitted.

Possible values:

  • An absolute URL - points to another web site (like action="http://www.example.com/example.htm")
  • A relative URL - points to a file within a web site (like action="example.htm")

HTML <form> autocomplete Attribute

Example -

<form action="/action_page.php" method="get" autocomplete="on">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="email">Email:</label>
<input type="text" id="email" name="email"><br><br>
<input type="submit">
</form>

Definition and Usage

The autocomplete attribute specifies whether a form should have autocomplete on or off.

When autocomplete is on, the browser automatically complete values based on values that the user has entered before.

Tip: It is possible to have autocomplete "on" for the form, and "off" for specific input fields, or vice versa.

Syntax

<form autocomplete="on|off">

Attribute Values

Value Description
on Default. The browser will automatically complete values based on values that the user has entered before
off The user must enter a value into each field for every use. The browser does not automatically complete entries

HTML <form> enctype Attribute

Example

<form action="/action_page_binary.asp" method="post" enctype="multipart/form-data">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>

Definition and Usage

The enctype attribute specifies how the form-data should be encoded when submitting it to the server.

Note: The enctype attribute can be used only if method="post".

Syntax

<form enctype="value">

Attribute Values

Value Description
application/x-www-form-urlencoded Default. All characters are encoded before sent (spaces are converted to "+" symbols, and special characters are converted to ASCII HEX values)
multipart/form-data This value is necessary if the user will upload a file through the form
text/plain Sends data without any encoding at all. Not recommended

s

HTML <form> method Attribute

Example

<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>

Definition and Usage

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

The form-data can be sent as URL variables (with method="get") or as HTTP post transaction (with method="post").

Notes on GET:

Notes on POST:

Syntax

<form method="get|post">

Attribute Values

Value Description
get Default. Appends the form-data to the URL in name/value pairs: URL?name=value&name=value
post

Sends the form-data as an HTTP post transaction

HTML <form> name Attribute

Example

<form action="/action_page.php" method="get" name="myForm">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="button" onclick="formSubmit()" value="Send form data!">
</form>

Definition and Usage

The name attribute specifies the name of a form.

The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted.

Syntax

<form name="text">

Attribute Values

ValueDescription
textSpecifies the name of the form

HTML <form> novalidate Attribute

Example

<form action="/action_page.php" novalidate>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit">
</form>

Definition and Usage

The novalidate attribute is a boolean attribute.

When present, it specifies that the form-data (input) should not be validated when submitted.

Syntax

<form novalidate>

HTML <form> rel Attribute

Definition and Usage

The rel attribute specifies the relationship between the current document and the linked document.

Syntax

<form rel="value">

Attribute Values

ValueDescription
externalSpecifies that the referenced document is not a part of the current site
helpLinks to a help document
licenseLinks to copyright information for the document
nextThe next document in a selection
nofollowLinks to an unendorsed document, like a paid link.
("nofollow" is used by Google, to specify that the Google search spider should not follow that link)
noopener
noreferrerSpecifies that the browser should not send a HTTP referrer header if the user follows the hyperlink
opener
prevThe previous document in a selection
search

Links to a search tool for the document

HTML <form> target Attribute

Example

<form action="/action_page.php" method="get" target="_blank">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
</form>

Definition and Usage

The target attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.

The target attribute defines a name of, or keyword for, a browsing context (e.g. tab, window, or inline frame).

Syntax

<form target="_blank|_self|_parent|_top|framename">

Attribute Values

ValueDescription
_blankThe response is displayed in a new window or tab
_selfThe response is displayed in the same frame (this is default)
_parentThe response is displayed in the parent frame
_topThe response is displayed in the full body of the window
framenameThe response is displayed in a named iframe