# Changing character encoding “utf-8” and reparsing.

> Canonical HTML version: https://rocketvalidator.com/html-validation/changing-character-encoding-utf-8-and-reparsing
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The HTML document's character encoding was not declared before the parser encountered non-ASCII content, forcing the validator to restart parsing with UTF-8 encoding.

When a browser or validator processes an HTML document, it needs to know the character encoding as early as possible. If the encoding isn't declared — or is declared too late in the document — the parser may initially guess the wrong encoding and then have to restart when it detects UTF-8 content. This warning typically appears when:

- The `<meta charset="utf-8">` declaration is missing entirely.
- The `<meta charset="utf-8">` tag is placed after other elements like `<title>` or `<script>` that contain non-ASCII characters (e.g., accented letters, emoji, or special symbols).
- The server sends a conflicting or missing `Content-Type` HTTP header.

The `<meta charset="utf-8">` tag must appear within the first 1024 bytes of the document and should be the **first child** of the `<head>` element, before any other elements that contain text content.

## Incorrect Example

```html
<!DOCTYPE html>
<html lang="fr">
  <head>
    <title>Café résumé</title>
    <meta charset="utf-8">
  </head>
  <body>
    <p>Bienvenue au café!</p>
  </body>
</html>
```

Here, the `<title>` contains non-ASCII characters (`é`) before the charset declaration, triggering the reparsing warning.

## Fixed Example

```html
<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <title>Café résumé</title>
  </head>
  <body>
    <p>Bienvenue au café!</p>
  </body>
</html>
```

Moving `<meta charset="utf-8">` to the very first position inside `<head>` ensures the parser knows the encoding before it encounters any non-ASCII characters.
