W3docs

HTML accept-charset Attribute

The HTML accept-charset attribute specifies the character encoding that must be used for the form submission. See how to use it on the <form> element.

The HTML accept-charset attribute specifies the character encoding (charset) that the browser should use when it submits a form to the server.

You can use this attribute only on the <form> element — it has no meaning on inputs, buttons, or any other tag. Its value is a space- or comma-separated list of one or more character encodings. The default value is UNKNOWN, which tells the browser to use the same encoding as the document that contains the form. You never need to write accept-charset="UNKNOWN" literally: that default is what you get by omitting the attribute entirely.

Why this attribute exists

To understand accept-charset, you have to picture the web before UTF-8 became universal. In the late 1990s and 2000s, documents were commonly served in single-byte encodings such as ISO-8859-1 (Western European), Shift_JIS (Japanese), or windows-1251 (Cyrillic). A page in one encoding might post data to a server that expected another, and a form field containing characters the target encoding could not represent would arrive on the server as garbled bytes (mojibake). accept-charset was the escape hatch: it let an author say "encode this form's submission as this charset, no matter what encoding the page itself uses."

That mismatch is the only situation in which the attribute ever mattered — a page in one legacy encoding feeding a backend that wanted a different one. Once the entire stack standardized on UTF-8, the problem disappeared.

Important — this attribute is effectively a no-op today. In practice every modern browser submits form data using the document's own encoding — UTF-8 for any modern page — regardless of accept-charset. (The HTML form-submission algorithm does define how a listed encoding would be picked, but since today's pages and browsers are UTF-8 end to end, the attribute changes nothing.) For new pages, the reliable way to control encoding is to serve your document as UTF-8 (with <meta charset="UTF-8">) and let the browser submit UTF-8 — you almost never need accept-charset at all.

Syntax

<form accept-charset="character_set"></form>

Common character set values

ValueDescription
UTF-8Universal Unicode encoding. The default behavior of every modern browser and the recommended value for virtually all forms.
ISO-8859-1Latin-1, a legacy 8-bit encoding for Western European languages. Cannot represent most non-Latin characters; only relevant for old systems.
UNKNOWNThe default. Tells the browser to use the same encoding as the document containing the form.

You may list more than one encoding (for example accept-charset="UTF-8 ISO-8859-1"); the browser is expected to pick the first one it can support. In modern browsers this list is effectively ignored.

Modern, correct usage

For virtually every form you write today, the right approach is to do nothing special: serve the page as UTF-8 and omit accept-charset. The form then submits UTF-8 automatically, which is what your server should expect.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Contact form</title>
  </head>
  <body>
    <!-- No accept-charset needed: UTF-8 page submits as UTF-8 -->
    <form action="/contact" method="post">
      <input type="text" name="name" placeholder="Your name" />
      <input type="email" name="email" placeholder="Your email" />
      <input type="submit" value="Send" />
    </form>
  </body>
</html>

If you prefer to be explicit, writing accept-charset="UTF-8" is harmless and documents your intent — but it changes nothing, because UTF-8 is already the behavior.

Example of the HTML accept-charset attribute

The example below sets accept-charset="ISO-8859-1", a legacy encoding, to illustrate the attribute's syntax. Note that current browsers will submit this form as UTF-8 anyway — this is a demonstration, not a recommendation.

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      input {
        display: block;
        margin-bottom: 10px;
      }
    </style>
  </head>
  <body>
    <form action="/form/submit" accept-charset="ISO-8859-1" method="post">
      <input type="text" name="name" placeholder="Enter your Name" />
      <input type="text" name="surname" placeholder="Enter your Surname" />
      <input type="number" name="age" placeholder="Enter your Age" />
      <input type="submit" value="Send" />
    </form>
  </body>
</html>

The accept-charset attribute works alongside the other attributes you set on a <form>:

  • action — the URL the form data is sent to.
  • method — the HTTP method (GET or POST) used to submit the form.
  • <form> tag — the container element these attributes belong to.

The related enctype attribute (set on the <form>) controls how the form data is encoded (for example multipart/form-data for file uploads), which is a separate concern from the character encoding that accept-charset describes. See the HTML Forms chapter for the full picture, including enctype.

What if I really must support a legacy non-UTF-8 server?

Because browsers ignore accept-charset, you cannot force a UTF-8 page to submit ISO-8859-1 (or any other charset) just by setting the attribute — that path is a dead end. If you are stuck with an old backend that only understands a single-byte encoding, the correct fix lives on the server, not in the HTML:

  • Convert on the server. Receive the UTF-8 submission and transcode it to the legacy encoding your application needs (for example with PHP's mb_convert_encoding, Python's bytes.decode/encode, or your platform's equivalent). This is the modern, recommended approach.
  • Migrate the backend to UTF-8 wherever you can — it removes the whole class of problem permanently.

Treating the submission as UTF-8 on the wire and converting at the boundary is reliable; relying on accept-charset to do it for you is not.

Practice

Practice
What is the HTML 'accept-charset' attribute?
What is the HTML 'accept-charset' attribute?
Practice
On which element can you use the accept-charset attribute?
On which element can you use the accept-charset attribute?
Practice
What happens in a modern browser if you omit accept-charset on a UTF-8 page?
What happens in a modern browser if you omit accept-charset on a UTF-8 page?
Was this page helpful?