# Bad value “text/html; charset=windows-1251” for attribute “content” on element “meta”: “charset=” must be followed by “utf-8”.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-text-html-charset-windows-1251-for-attribute-content-on-element-meta-charset-must-be-followed-by-utf-8
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The HTML5 specification mandates UTF-8 as the only permitted character encoding for web documents declared via `<meta>` tags. Legacy encodings such as `windows-1251` (a Cyrillic character encoding), `iso-8859-1`, `shift_jis`, and others are no longer valid values in HTML5 `<meta>` declarations. This restriction exists because UTF-8 is a universal encoding that can represent virtually every character from every writing system, eliminating the interoperability problems that plagued the web when dozens of competing encodings were in use.

When the validator encounters `content="text/html; charset=windows-1251"` on a `<meta>` element, it flags it because the `charset=` portion must be followed by `utf-8` — no other value is accepted. This applies whether you use the longer `<meta http-equiv="Content-Type">` syntax or the shorter `<meta charset>` syntax.

### Why this matters

- **Standards compliance:** The WHATWG HTML Living Standard explicitly requires `utf-8` as the character encoding when declared in a `<meta>` tag. Non-conforming encodings will trigger validation errors.
- **Internationalization:** UTF-8 supports all Unicode characters, making your pages work correctly for users across all languages, including Cyrillic text that `windows-1251` was originally designed for.
- **Security:** Legacy encodings can introduce security vulnerabilities, including certain cross-site scripting (XSS) attack vectors that exploit encoding ambiguity.
- **Browser consistency:** While browsers may still recognize legacy encodings, relying on them can cause mojibake (garbled text) when there's a mismatch between the declared and actual encoding.

### How to fix it

1. **Update the `<meta>` tag** to declare `utf-8` as the charset.
2. **Re-save your file** in UTF-8 encoding using your text editor or IDE. Most modern editors support this — look for an encoding option in "Save As" or in the status bar.
3. **Verify your server configuration.** If your server sends a `Content-Type` HTTP header with a different encoding, the server header takes precedence over the `<meta>` tag. Make sure both agree on UTF-8.
4. **Convert your content.** If your text was originally written in `windows-1251`, you may need to convert it to UTF-8. Tools like `iconv` on the command line can help: `iconv -f WINDOWS-1251 -t UTF-8 input.html > output.html`.

## Examples

### ❌ Incorrect: Using `windows-1251` charset

```html
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
```

### ✅ Correct: Using `utf-8` with `http-equiv` syntax

```html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
```

### ✅ Correct: Using the shorter `<meta charset>` syntax (preferred in HTML5)

```html
<meta charset="utf-8">
```

### Full document example

```html
<!DOCTYPE html>
<html lang="ru">
  <head>
    <meta charset="utf-8">
    <title>Пример страницы</title>
  </head>
  <body>
    <p>Текст на русском языке в кодировке UTF-8.</p>
  </body>
</html>
```

The shorter `<meta charset="utf-8">` syntax is generally preferred in HTML5 documents because it's more concise and achieves the same result. Whichever syntax you choose, place the charset declaration within the first 1024 bytes of your document — ideally as the very first element inside `<head>` — so browsers can detect the encoding as early as possible.
