About This HTML Issue
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 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
-
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. -
Update the
<meta>tag to declareutf-8instead ofwindows-1251. -
Prefer the shorter
charsetsyntax introduced in HTML5, which is simpler and equivalent to the olderhttp-equivform. -
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:
<head>
<meta charset="windows-1251">
<title>My Page</title>
</head>
Or using the older http-equiv syntax:
<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:
<head>
<meta charset="utf-8">
<title>My Page</title>
</head>
Or using the equivalent http-equiv form:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>My Page</title>
</head>
✅ Correct: full document example
<!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.
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.