Search code examples
phphtmlcharacter-encodingw3cw3c-validation

W3C declaration is missing


I make multilanguage webpage, I use HTML5 and I get error why I try to validate in W3C:

Line 4, Column 11: No explicit character encoding declaration has been seen yet (assumed utf-8) but the document contains non-ASCII.

<title>Viešbutis Graikijoje</titl…

..however my header contains utf-8 charset:

<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo $title?></title>
<meta name="robots" content="index, follow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

I read other posts, it says you need use utf-8 charset, but I do use it.. I also tried put

    AddType 'text/html; charset=UTF-8' html

..in .htaccess file, but it does not working. Any ideas?


Solution

  • You have non-ascii characters in the <title>, but your <meta> tag declaring the document to be UTF8 has not yet appeared.

    Move the content type <meta> tag to the first element in the <head>:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><?php echo $title?></title>
    <meta name="robots" content="index, follow" />
    

    While the AddType directive in the .htaccess is good idea if (and only if) every single document with a .html extension served from that directory is HTML with a character set of UTF8, the W3 Validators will still want you to explicitly declare the character set in the document.

    Also note that when writing XHTML, they will permit you to declare it in an XML declaration:

    <?xml version="1.0" encoding="utf-8" ?>