HTML accept-charset Attribute

Description

The accept-charset attribute specifies the character encodings that are to be used for the form submission. This attribute is used within a <form> element to dictate which character sets the server is willing to accept for the form data. When a form is submitted, the browser uses the accept-charset attribute to encode the form data before sending it to the server.

If the accept-charset attribute is not specified, the form data will be transmitted using the charset of the document containing the form, or the default charset of the browser if the document does not specify one. Specifying this attribute can be particularly important for ensuring the correct interpretation of form input on the server, especially when dealing with internationalized content that may include characters outside of the ASCII range.

The value of this attribute can be a single charset, such as UTF-8, or a comma-separated list of charsets, indicating the server’s preference order. For example, accept-charset="UTF-8, ISO-8859-1" would indicate that the server prefers UTF-8 encoding but will also accept ISO-8859-1 if necessary.

Example usage in a form:

<form action="example.php" method="post" accept-charset="UTF-8">
  <!-- form elements here -->
</form>

In this example, the form data will be encoded as UTF-8 when submitted to the server, ensuring that any characters, including those outside the ASCII range, are correctly encoded and interpreted by the server.

Syntax

<form accept-charset="character-set">

Values

  • character-setSpace-separated list of character encodings. Common values are UTF-8 and ISO-8859-1. The default value is 'unknown'. For HTML5 pages this means that UTF-8 will be used.

Applies To

The accept-charset attribute can be used on the following html elements.

Example

<form action="formscript.php" accept-charset="UTF-8 ISO-8859-1">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name">
<br><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message"></textarea>
<br><br>
<button type="submit">Submit</button>
</form>

Browser Support

The following table will show you the current browser support for the HTML accept-charset Attribute.

Desktop
Edge Chrome Firefox Opera Safari
1211153
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18414214.4

Last updated by CSSPortal on: 28th March 2024