accept-charset
accept-charset attribute
The accept-charset
attribute in HTML specifies the character encodings to be used when submitting a form. Placed within a <form>
element, it indicates which encodings the server can process for the form data. When the form is submitted, the browser encodes the data with the chosen encoding before sending it to the server.
Syntax
<form accept-charset="character-set">
If the accept-charset
attribute is not specified, the form will use the default charset of the document or browser.
It can either be a single charset (e.g., UTF-8
) or a list of charsets separated by commas (e.g., accept-charset="UTF-8, ISO-8859-1"
).
Example
<h1>The form accept-charset attribute</h1>
<form 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>
Definition and Usage
The accept-charset
attribute defines the character encodings to be used when submitting a form.
By default, it is set to the reserved value "UNKNOWN," which means the encoding matches the document's encoding containing the <form>
element.
Values
accept-charset
- A space-separated list of character encodings, such as
UTF-8
andISO-8859-1
. By default, it is set to 'unknown', meaningUTF-8
is used for HTML5 pages.
- A space-separated list of character encodings, such as
Applies To
The accept-charset
attribute can be used with the following element: <form>
.
Elements | Attributes |
---|---|
<form> | accept-charset |
Conclusion
The accept-charset
attribute was used to define which character encodings should be used when submitting form data. However, it is no longer supported in HTML5. In HTML5, the default encoding for form submissions is UTF-8
.
Form
The form attribute in HTML connects an input or form element to a different form, providing flexibility in positioning elements while allowing them to be submitted together as part of the same form.
action
The action attribute in HTML forms defines the URL where the form data will be sent. The method attribute determines how the data is transmitted, either using GET or POST.