HTML accept-charset Attribute
The HTML accept-charset attribute specifies the character encoding to use when form data is submitted. It is used on the <form> element, and in modern HTML its value must be UTF-8.
Syntax
The accept-charset attribute is placed in the opening <form> tag. In modern HTML, its value must be an ASCII case-insensitive match for UTF-8.
<form action="form.php" method="post" accept-charset="UTF-8">
...
</form>
Attribute Value
| Value | Description |
|---|---|
UTF-8 |
Specifies UTF-8 as the character encoding used for the form submission. |
Modern HTML allows only UTF-8 as the value of the accept-charset attribute. The value is matched without regard to uppercase or lowercase letters.
Elements That Use the accept-charset Attribute
The accept-charset attribute is currently valid on the <form> element.
| Element | Description |
|---|---|
<form> |
Specifies the character encoding to use when the form data is submitted. |
Using the accept-charset Attribute
The following example specifies UTF-8 as the character encoding for the form submission:
<form action="form.php" method="post" accept-charset="UTF-8">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<button type="submit">Submit</button>
</form>
The accept-charset="UTF-8" value does not create a visible change to the form. It provides information used when the browser prepares the form data for submission.
UTF-8 and Modern HTML
UTF-8 can represent characters from languages and writing systems around the world and is the standard character encoding used for modern web content. Modern HTML therefore restricts the accept-charset attribute to UTF-8.
<form accept-charset="UTF-8">
...
</form>
A web page commonly declares UTF-8 as its own character encoding with <meta charset="utf-8">. The accept-charset attribute serves a different purpose: it concerns the encoding used for form submission.
Older HTML Versions
Older versions of HTML allowed the accept-charset attribute to specify more than one character encoding. Modern HTML no longer permits authors to provide a list of different encodings and instead requires UTF-8 when the attribute is present.
<!-- Modern HTML -->
<form accept-charset="UTF-8">
...
</form>
Older examples that contain multiple character encodings should not be copied into modern HTML documents.
Common Mistakes
Do not provide a list of character encodings in the accept-charset attribute. Although older HTML versions permitted multiple encodings, modern HTML requires UTF-8.
<!-- Correct -->
<form accept-charset="UTF-8">
...
</form>
Do not confuse accept-charset with the charset attribute used by the <meta> element. The charset attribute declares the character encoding of the HTML document, while accept-charset concerns form submission.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
The accept-charset attribute on the <form> element is widely supported in current core browsers.
Checking Browser Support
For current browser compatibility information, visit Can I Use? . Search for the HTML element or attribute you want to check. You can also narrow your search by entering an element name and attribute name separated by a colon. Search results can include related HTML features, element attributes, input types, APIs, and other technologies, so select the result that most closely matches the feature you are checking.
Try the accept-charset Attribute
The example uses accept-charset="UTF-8" on a form. The attribute does not change the visible appearance of the form, but you can examine its placement and edit the form controls in the editor.
Summary
The HTML accept-charset attribute specifies the character encoding used for form submission. It is used on the <form> element, and when present in modern HTML, its value must be UTF-8. Older HTML allowed multiple character encodings, but those values should not be used in modern documents.
