# Changing encoding at this point would need non-streamable behavior.

> Canonical HTML version: https://rocketvalidator.com/html-validation/changing-encoding-at-this-point-would-need-non-streamable-behavior
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

Changing the character encoding declaration too late in the document prevents the browser from processing it correctly. The `<meta charset>` declaration must appear within the first 1024 bytes of the HTML document, and specifically before any non-ASCII content.

When a browser parses an HTML document, it reads the bytes as a stream. If it encounters a `<meta charset>` tag after it has already started interpreting content, it would need to go back and re-parse everything from the beginning — this is "non-streamable behavior." To avoid this, the HTML specification requires that the charset declaration appear very early in the document.

The most common causes of this error are:

- Placing `<meta charset>` after other large `<meta>` tags, long `<title>` content, or `<script>` blocks in the `<head>`.
- Placing `<meta charset>` after content that pushes it beyond the 1024-byte boundary.
- Including it in the `<body>` instead of the `<head>`.

The fix is simple: make `<meta charset="utf-8">` the **very first element** inside `<head>`, before any other elements.

## Incorrect Example

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>A very long title that takes up many bytes and pushes the charset declaration further down in the document stream...</title>
    <meta name="description" content="A very long description with lots of text that consumes bytes before the charset is declared...">
    <meta charset="utf-8">
  </head>
  <body>
    <p>Hello world</p>
  </body>
</html>
```

## Corrected Example

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>A very long title that takes up many bytes...</title>
    <meta name="description" content="A very long description with lots of text...">
  </head>
  <body>
    <p>Hello world</p>
  </body>
</html>
```

Always keep `<meta charset="utf-8">` as the first child of `<head>`. This ensures the browser knows the encoding before it processes any other content.
