Search code examples
javascripthtmlutf-8character-encodingmeta

The character encoding declaration of the HTML document was not found


randomly getting this issue come up in my web console of firefox (is the js tab)

Its only just appeared and cant link it to any changes i have made.

The full error is:

The page was reloaded, because the character encoding declaration of the HTML document was not found when prescanning the first 1024 bytes of the file. The encoding declaration needs to be moved to be within the first 1024 bytes of the file.

Or this one:

The character encoding declaration of the HTML document was not found when prescanning the first 1024 bytes of the file. When viewed in a differently-configured browser, this page will reload automatically. The encoding declaration needs to be moved to be within the first 1024 bytes of the file.

The issue points to this line:

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

To me, that meta tag is okay? Any help as i think it is conflicting and causing issues with other things.

Craig


Solution

  • Charset is a parameter of the content-type, not a separate attribute:

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

    Or, if you want to use the HTML 5 style:

    <meta charset="utf-8">
    

    You should also note the error message:

    not found when prescanning the first 1024 bytes of the file

    You might need to move the meta tag up the document. Ideally, it should be the first tag inside the <head>.