HTML / HTML Attributes

HTML Accept-Charset Attribute

Dec 12, 2022
2 min read
HTML accept-charset Attribute

Definition

The accept-charset Attribute specifies the character encoding to be used for a <form> submission.

Applicable Elements

The accept-charset Attribute can be used with the following elements:

HTML <form> accept-charset Attribute

The <form> tag is used to create an HTML form that contains controls for submitting user information.

The accept-charset attribute specifies the space-separated character encodings accepted by the server for the <form> submission.

Syntax

<form accept-charset="UTF-8"></form>

Usage

  • The accept-charset attribute accepts space-separated character encodings. Common values include:
    • UTF-8 - Unicode character encoding.
    • ISO-8859-1 - Latin alphabet character encoding.
  • The recommended character set for HTML5 is Unicode UTF-8.
  • The character set for a web page is usually set out in the <head> using the <meta> tag:
    <meta charset="UTF-8">
    If the <form> element does not set an accept-charset attribute, it will default to the documents character encoding. For most forms, an accept-charset attribute is not required for this reason.
  • The accept-charset attribute is ASCII case-insensitive.
  • You can specify multiple accept-charset encodings separated by a space. The order of the character sets matters. For instance, you may have a preferred set of character encodings if someone types Hebrew letters in your form, but you also want to have UTF-8 as a backup.

Values

The HTML5 recommended value is:

  • UTF-8

But you can use any character encoding set. See here for a full list.

Examples

The following example shows a form that accepts the UTF-8 character encoding:

<form accept-charset="UTF-8" action="" method="get" class="form">
  <fieldset class="fieldset">
    <label for="name">Name: </label>
    <input type="text" name="name" id="name">
  </fieldset>
  <div class="form-example">
    <input type="submit" value="Subscribe!">
  </div>
</form>

An example showing multiple accept-charset declarations. The primary encoding is Hebrew, with UTF-8 as secondary:

<form accept-charset="ISO-8859-8 UTF-8" action="" method="get" class="form">
  <fieldset class="fieldset">
    <label for="name">Name: </label>
    <input type="text" name="name" id="name">
  </fieldset>
  <div class="form-example">
    <input type="submit" value="Subscribe!">
  </div>
</form>

Specification

The accept-charset HTML specification for the <form> element is as follows:

Browser Support

The accept-charset has the following browser support:

Desktop

ChromeEdgeFirefoxIEOperaSafari
<accept-charset>YesYesYesYesYesYes

Mobile

Android WebviewChrome AndroidFirefox AndroidOpera AndroidiOS SafariSamsung Internet
<accept-charset>YesYesYesYesYesYes