# Internal encoding declaration “windows-1251” disagrees with the actual encoding of the document (“utf-8”).

> Canonical HTML version: https://rocketvalidator.com/html-validation/internal-encoding-declaration-windows-1251-disagrees-with-the-actual-encoding-of-the-document-utf-8
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

When a browser loads an HTML document, it needs to know which character encoding to use to correctly interpret the bytes in the file. The `<meta>` tag's `charset` attribute (or the `http-equiv="Content-Type"` declaration) tells the browser what encoding to expect. If this declaration says `windows-1251` but the file is actually saved as `utf-8`, the browser faces conflicting signals — the declared encoding disagrees with the actual byte content.

This mismatch matters for several reasons:

- **Broken text rendering:** Characters outside the basic ASCII range (such as accented letters, Cyrillic, CJK characters, emoji, and special symbols) may display as garbled or replacement characters (often seen as `Ð` sequences, `�`, or other mojibake).
- **Data integrity:** Form submissions and JavaScript string operations may produce corrupted data if the browser interprets the encoding incorrectly.
- **Standards compliance:** The [WHATWG HTML Living Standard](https://html.spec.whatwg.org/multipage/semantics.html#charset) requires that the encoding declaration match the actual encoding of the document. Validators flag this mismatch as an error.
- **Inconsistent behavior:** Different browsers may handle the conflict differently — some may trust the `<meta>` tag, others may sniff the actual encoding — leading to unpredictable results across user agents.

## How to fix it

1. **Determine the actual encoding of your file.** Most modern text editors (VS Code, Sublime Text, Notepad++) display the file encoding in the status bar. If your file is saved as UTF-8 (which is the recommended encoding for all new web content), your `<meta>` tag must reflect that.

2. **Update the `<meta>` tag** to declare `utf-8` instead of `windows-1251`.

3. **Prefer the shorter `charset` syntax** introduced in HTML5, which is simpler and equivalent to the older `http-equiv` form.

4. **Place the encoding declaration within the first 1024 bytes** of the document, ideally as the first element inside `<head>`, so the browser encounters it before parsing other content.

## Examples

### ❌ Incorrect: declared encoding doesn't match actual file encoding

The file is saved as UTF-8 but the `<meta>` tag declares `windows-1251`:

```html
<head>
  <meta charset="windows-1251">
  <title>My Page</title>
</head>
```

Or using the older `http-equiv` syntax:

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

### ✅ Correct: declared encoding matches the actual UTF-8 file

Using the modern HTML5 `charset` attribute:

```html
<head>
  <meta charset="utf-8">
  <title>My Page</title>
</head>
```

Or using the equivalent `http-equiv` form:

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

### ✅ Correct: full document example

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

### What if you actually need `windows-1251`?

If your content genuinely requires `windows-1251` encoding (for example, a legacy Cyrillic text file), you need to re-save the file in `windows-1251` encoding using your text editor. However, UTF-8 is strongly recommended for all web content because it supports every Unicode character and is the default encoding for HTML5. Converting your file to UTF-8 and updating the `<meta>` tag accordingly is almost always the better path forward.
