Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

accept-charset — form submission encoding

The form attribute `accept-charset` selects the character encoding for submission; the conforming modern value is `UTF-8`.

Version: HTML Living Standard

Syntax

<form method="post" action="/capture" accept-charset="UTF-8">

Use accept-charset="UTF-8" on form. The standard accepts this value case-insensitively in ASCII, not the older list of several encodings. It does not select a language or restrict characters entered into controls.

Document encoding and submission encoding serve different purposes. meta charset describes the document, whereas enctype selects the data format, such as URL-encoded or multipart form data. The backend must decode the received bytes using that format.

The example POSTs Zażółć to the local /capture fixture. It returns the exact received body; non-ASCII characters become percent-encoded UTF-8 bytes. The special hidden _charset_ control receives UTF-8 instead of its initial unset. The receiver belongs to the test, not a public service.

Examples

<!doctype html><meta charset="utf-8">
<form id="form" method="post" action="/capture" accept-charset="UTF-8" target="receipt">
<label>Text <input name="text" value="Zażółć"></label>
<input type="hidden" name="_charset_" value="unset">
<button>Send</button></form>
<iframe name="receipt" id="receipt" title="Submission receipt" hidden></iframe>
<output id="result"></output>
<script>
const frame = document.querySelector('#receipt');
frame.addEventListener('load', () => {
  const response = frame.contentDocument.querySelector('#received');
  if (response) document.querySelector('#result').textContent = response.textContent;
});
document.querySelector('form').requestSubmit();
</script>

Result

text=Za%C5%BC%C3%B3%C5%82%C4%87&_charset_=UTF-8

The isolated test verifies an actual form submission, its entire URL-encoded body, and replacement of the hidden `_charset_` value.

Sources