How do I fix "Error: A charset attribute on a meta element found after the first 512 bytes."
Asked Answered
N

5

29

I am getting this error for my site in validation.

Error: A charset attribute on a meta element found after the first 512 bytes.

and here is code causing this problem:

<!DOCTYPE html> 
<html class="not-ie no-js" lang="en-US" prefix="og: http://ogp.me/ns#"> 
<head>
<link rel="stylesheet" type="text/css" href="http://mywebsite.com.au/wp-content/cache/minify/000000/TY3RDsIgDEV_SFb5pAqVgLDWFTb79y6bWXw6ybk3OR4KdcHwgsZxVFLYckzUL97uoN0q7QyqUN6DFpueOAd78Gdqef4ta47EruifwhEzS0WjZfWH97CJSw1FcjdHqOYSc6rkdqdnaU_LdRHW7k79BQ.css" media="all" />
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/hY7RDsIgDEV_aFCXmCzxb5DVDQSKtDj164W5dx977rltV5F8ATDevPRCtAQ02bG2FHcGwV0Z_KNiecOoJz0eg44uac_DCTxDpBlLcp-ibWWh-KNPNyMpz10dztBWRkyiCuaw14exsSTGirpRiWoCl2yoM3JvH2d68l9mW1wWbpJHycbe-0s1tHDLS6GVvg.js"></script>
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/M9YvzdTPKixNLarUK83UK89MSU8t0cvNzAMA.js"></script>
<script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/ZY5BDsIwDAQ_RNIWxEt4gUkMuKRxsJPS8HpacahQLnuYnZW270btFAO6TDN9xED0BpcsYH6URe1E8dBvoqAmjn4H46ugVIugFO9msKemukF09cqLTeCef42rLqCFEJqNTiD5krcI5FEagZQzJ2z46EC4rMf3BoonTgEqyjw0g8zFPS5vSrieP9rzLriimacv.js"></script>
<meta charset="UTF-8">
Nez answered 2/8, 2013 at 2:26 Comment(2)
As an aside, that test is out of date. The current authoring requirements are that The element containing the character encoding declaration must be serialized completely within the first 1024 bytes of the document.Ostracoderm
#4696999Celenacelene
S
32

Move the meta entry to above all those other entries, such as:

<!DOCTYPE html> 
<html class="not-ie no-js" lang="en-US" prefix="og: http://ogp.me/ns#"> 
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="http://mywebsite.com.au/wp-content/cache/minify/000000/TY3RDsIgDEV_SFb5pAqVgLDWFTb79y6bWXw6ybk3OR4KdcHwgsZxVFLYckzUL97uoN0q7QyqUN6DFpueOAd78Gdqef4ta47EruifwhEzS0WjZfWH97CJSw1FcjdHqOYSc6rkdqdnaU_LdRHW7k79BQ.css" media="all" />
    <script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/hY7RDsIgDEV_aFCXmCzxb5DVDQSKtDj164W5dx977rltV5F8ATDevPRCtAQ02bG2FHcGwV0Z_KNiecOoJz0eg44uac_DCTxDpBlLcp-ibWWh-KNPNyMpz10dztBWRkyiCuaw14exsSTGirpRiWoCl2yoM3JvH2d68l9mW1wWbpJHycbe-0s1tHDLS6GVvg.js"></script>
    <script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/M9YvzdTPKixNLarUK83UK89MSU8t0cvNzAMA.js"></script>
    <script type="text/javascript" src="http://mywebsite.com.au/wp-content/cache/minify/000000/ZY5BDsIwDAQ_RNIWxEt4gUkMuKRxsJPS8HpacahQLnuYnZW270btFAO6TDN9xED0BpcsYH6URe1E8dBvoqAmjn4H46ugVIugFO9msKemukF09cqLTeCef42rLqCFEJqNTiD5krcI5FEagZQzJ2z46EC4rMf3BoonTgEqyjw0g8zFPS5vSrieP9rzLriimacv.js"></script>

Your problem lies with your violations of the W3C HTML5 recommendation:

The element containing the character encoding declaration must be serialized completely within the first 1024 bytes of the document.

Whatever test you're using is somewhat out of date, the limit used to be 512 bytes but was changed (at the latest) December 2012.

Those rather chunky script tags are pushing the character set specification well outside the 512-byte range of your test tool. Even if you use a later test tool that recognises the change to 1024 bytes, it may still be a problem. The advice to put the meta tag up front should fix either case.

Synagogue answered 2/8, 2013 at 2:33 Comment(0)
V
10

Just put

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

like full sentence instead of only writing

<meta charset="UTF-8">

it works fine for me.

Vevina answered 14/10, 2013 at 9:2 Comment(1)
It will not validate as HTML5.Briarroot
H
1

Try putting the meta tag as the first thing inside head

Holp answered 2/8, 2013 at 2:34 Comment(0)
S
0

This error also occurs if you have the tag appearing more than once in the <head> code on the page. Check you have not inadvertently written this twice.

Solvolysis answered 14/7, 2015 at 17:43 Comment(0)
P
0

Just replace the meta with

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

it will work

Persevere answered 21/12, 2023 at 1:41 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Inefficacious

© 2022 - 2024 — McMap. All rights reserved.