👀 Live Preview
Form with accept-charset="UTF-8" for international text:

The accept-charset attribute is an essential part of HTML forms that determines which character encodings the server may use when processing submitted form data. By setting it, you help ensure text—including accented letters and non-Latin scripts—is interpreted correctly on the server.
Control submitted charset.
Modern web standard.
ISO-8859-1, Shift_JIS.
Where it applies.
JavaScript DOM property.
Document vs form data.
accept-charsetThe primary purpose of the accept-charset attribute is to define the character encodings that the server accepts for form submissions. This is crucial for ensuring the server can correctly interpret and handle the data sent from the form—especially when users enter international characters.
accept-charset affects how field values are encoded when the form is submitted. It does not change how the HTML page itself is decoded—that is controlled by <meta charset> or the HTTP Content-Type header.
Add accept-charset to a <form> element with one or more encoding names separated by spaces:
<form action="/submit" method="post" accept-charset="UTF-8">
<!-- form fields -->
</form><form> element.acceptCharset.The accept-charset attribute accepts a string representing one or more character encodings. Common values include:
UTF-8 — The most widely used encoding, supporting characters from virtually every language. Use this for all modern sites.ISO-8859-1 — A legacy encoding for Western European languages.Shift_JIS — Used for Japanese text in older systems.UTF-8 ISO-8859-1 — Space-separated list when multiple encodings are accepted.<!-- Single encoding (recommended) -->
<form accept-charset="UTF-8">...</form>
<!-- Multiple encodings -->
<form accept-charset="UTF-8 ISO-8859-1">...</form>| Use Case | accept-charset Value | Notes |
|---|---|---|
| Modern websites | UTF-8 | Default choice |
| Western European legacy | ISO-8859-1 | Older systems only |
| Japanese legacy | Shift_JIS | Legacy compatibility |
| Multiple options | UTF-8 ISO-8859-1 | Space-separated |
| JavaScript property | form.acceptCharset | camelCase in DOM |
| Applicable element | <form> | Form only |
accept-charset vs meta charset| Feature | accept-charset | meta charset |
|---|---|---|
| Applies to | Form submission data | HTML document bytes |
| Element | <form> | <meta> in <head> |
| When it takes effect | On form submit | When page loads |
| Typical value | UTF-8 | UTF-8 |
| Element | Supported? | Notes |
|---|---|---|
<form> | Yes | Primary and only standard use |
<input> | No | Set on the parent form instead |
<textarea> | No | Inherits form encoding on submit |
UTF-8 forms, dynamic encoding switches, and multiple accepted charsets.
Form with accept-charset="UTF-8" for international text:
Here’s a basic example illustrating how to use the accept-charset attribute in an HTML form:
<form action="/submit" method="post" accept-charset="UTF-8">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<input type="submit" value="Submit">
</form>In this example, the accept-charset attribute is set to UTF-8, indicating that form data should be encoded using UTF-8 when submitted to the server.
Similar to other HTML attributes, accept-charset can be dynamically modified using JavaScript based on user interaction or locale:
<script>
function setFormCharset(encoding) {
document.getElementById("dynamicForm").acceptCharset = encoding;
}
</script>The setFormCharset function updates the acceptCharset DOM property on the form with id dynamicForm. Note the camelCase property name in JavaScript versus the hyphenated HTML attribute.
List more than one accepted encoding when legacy server support is required:
<form action="/submit" method="post" accept-charset="UTF-8 ISO-8859-1">
<textarea name="message"></textarea>
<input type="submit" value="Submit">
</form>A space-separated list tells the server which encodings the form may use. For new projects, prefer a single UTF-8 value everywhere.
meta charset and accept-charset aligned.Declare UTF-8 or other encodings on the form element.
Field values are encoded using the specified charset before sending.
The backend interprets bytes using the accepted encoding list.
Accented and non-Latin characters arrive intact on the server.
The accept-charset attribute is supported in all modern browsers. HTML5 documents default to UTF-8 when the attribute is omitted.
All major browsers honor accept-charset on form submission.
Bottom line: Use accept-charset="UTF-8" on forms; align with your page charset and server settings.
accept-charset="UTF-8" on forms handling international textacceptCharset in JavaScript when locale changes dynamicallyaccept-charset with enctypeThe accept-charset attribute is a crucial aspect of HTML forms, influencing how the server interprets and processes submitted data. By understanding and using this attribute effectively, developers can ensure seamless communication between the client and server while handling diverse character sets.
For modern websites, declare UTF-8 on your pages and forms, and verify your server and database use the same encoding end to end.
accept-charsetBookmark these before your next internationalized form.
On <form> element.
ScopeModern default.
ValuesSubmit vs document.
ComparisonJavaScript property.
DynamicPage, form, server.
Best Practice<form> element. Set it on the form, not on individual inputs.meta charset decodes the HTML file. accept-charset encodes form data on submit.UTF-8 for virtually all modern websites. It supports every language and matches HTML5 defaults.formElement.acceptCharset = "UTF-8" (camelCase, no hyphen).Practice the accept-charset attribute with UTF-8 and dynamic encoding in the Try It editor.
5 people found this page helpful