Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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"> 
like image 265
Anon Avatar asked Aug 02 '13 02:08

Anon


People also ask

What does the charset attribute do in a meta tag?

The charset attribute specifies the character encoding for the HTML document. The HTML5 specification encourages web developers to use the UTF-8 character set, which covers almost all of the characters and symbols in the world!

Does meta charset require UTF-8?

It doesn't matter which you use, but it's easier to type the first one. It also doesn't matter whether you type UTF-8 or utf-8 . You should always use the UTF-8 character encoding. (Remember that this means you also need to save your content as UTF-8.)

Which syntax of meta charset is correct for HTML5?

You can use a <meta> element with a charset attribute that specifies the encoding within the first 512 bytes of the HTML5 document. Above syntax replaces the need for <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> although that syntax is still allowed.


2 Answers

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.

like image 70
paxdiablo Avatar answered Sep 27 '22 18:09

paxdiablo


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.

like image 42
Hugo Rush Avatar answered Sep 27 '22 18:09

Hugo Rush