The HTML accept-charset attribute
The accept-charset attribute sets a form's submission encoding, and UTF-8 is the only value the HTML standard allows. On a page that is already UTF-8, that value changes nothing. It matters on a page served in an older encoding, where it switches the form's data to UTF-8.
Overview
The HTML accept-charset attribute chooses the character encoding for the text a form submits. UTF-8 is the one encoding name permitted here, and letter case doesn't matter.
The attribute once took several encodings, separated by commas or spaces. Validators now reject any other value, such as ISO-8859-1, with the message that utf-8 is the only allowed value.
The default comes from the page. With no accept-charset, the browser encodes the data in the page's own encoding, so a page with <meta charset="utf-8"> already sends UTF-8 and a windows-1252 page sends windows-1252.
Browsers still act on old values. A form with accept-charset="ISO-8859-1" sends windows-1252, the encoding that the ISO-8859-1 label maps to on the web.
Syntax
<form action="/signup" method="post" accept-charset="UTF-8">
<label for="city">City</label>
<input id="city" name="city">
<button>Sign up</button>
</form>
Values
| Value |
|---|
UTF-8 in any letter case, the only value HTML allows. |
Example
<form id="signup" action="data:text/html;charset=windows-1252,%3Cscript%3Eparent.postMessage(location.search,'*')%3C/script%3E" target="sent" accept-charset="UTF-8">
<input type="hidden" name="_charset_">
<label for="city">City</label>
<input id="city" name="city" value="São Paulo ✓"><br>
<label for="value">accept-charset</label>
<select id="value">
<option>UTF-8</option>
<option>ISO-8859-1</option>
</select>
<button>Sign up</button>
</form>
<iframe name="sent" title="Submission target" hidden></iframe>
<p id="out" role="status" style="overflow-wrap:anywhere"></p>
<p>Press Sign up, choose the old value ISO-8859-1 and press it again. The form really submits to a hidden frame, which reports the query it received.</p>
<script>
const form = document.getElementById('signup');
document.getElementById('value').addEventListener('change', function () {
form.setAttribute('accept-charset', this.value);
});
form.addEventListener('submit', function (e) {
e.preventDefault();
const old = document.querySelector('iframe[name="sent"]');
old.replaceWith(old.cloneNode());
form.submit();
});
window.addEventListener('message', function (e) {
if (e.source !== document.querySelector('iframe[name="sent"]').contentWindow) return;
document.getElementById('out').textContent = 'The form sent ' + e.data.slice(1);
});
</script>
Best practices
- On a legacy page that can't move to UTF-8 yet, add
accept-charset="UTF-8"to each form. Its data then reaches the server as UTF-8, whatever encoding the page itself uses. - Write the value as UTF-8 alone. For an old list such as
UTF-8, ISO-8859-1, Chrome sends UTF-8, while Firefox splits only on spaces, as the HTML standard does, and sends windows-1252. - Include a hidden input named
_charset_with no value when pages in different encodings post to one URL. The browser fills it with the encoding it used, such as UTF-8, so the server knows how to decode the rest. - Test a form by submitting a check mark. UTF-8 sends it as
%E2%9C%93, while a windows-1252 form sends the text✓, which a server can't tell apart from someone typing those characters.























