# The only allowed value for the “charset” attribute for the “meta” element is “utf-8”.

> Canonical HTML version: https://rocketvalidator.com/html-validation/the-only-allowed-value-for-the-charset-attribute-for-the-meta-element-is-utf-8
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `meta` element's `charset` attribute only accepts `utf-8` as its value in HTML5.

Older HTML versions and XHTML allowed character encodings like `windows-1252`, `iso-8859-1`, or `shift_jis` in the `charset` attribute. The HTML living standard restricts this to `utf-8` only. UTF-8 is the required character encoding for HTML5 documents, and the W3C validator enforces this rule.

If a document actually uses a different encoding, convert the file to UTF-8 using a text editor or command line tool, then update the `meta` tag accordingly. Most modern text editors can save files as UTF-8.

The `<meta charset="utf-8">` declaration should appear as early as possible within the `<head>` element, ideally as the first child. It must appear within the first 1024 bytes of the document so that browsers can detect the encoding before parsing the rest of the content.

## HTML examples

### Invalid charset value

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="windows-1252">
    <title>Example</title>
  </head>
  <body>
    <p>Hello world</p>
  </body>
</html>
```

### Valid charset value

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example</title>
  </head>
  <body>
    <p>Hello world</p>
  </body>
</html>
```
