Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this HTML5 document invalid?

Tags:

html

I'm getting pretty confused about an error message I'm getting when I try to validate any simple HTML document without a meta encoding like this:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>Test</body>
</html>

The W3C validator http://validator.w3.org reluctantly accepts the document as valid with just a few warnings when it is pasted into the direct input form, but when the document is uploaded or loaded by URI, validation fails with this error message

The character encoding was not declared. Proceeding using windows-1252.

There are two things I don't understand about this error:

  • Why is a missing character encoding considered an error, when fallback rules exist?
  • Why is the validator assuming windows-1252 instead of UTF-8, like any browser would?

Can someone explain these two points please? I'm pretty new to this stuff, so please bear with me.

like image 360
Kath Brown Avatar asked Jul 29 '13 23:07

Kath Brown


1 Answers

Well, it depends on what you are using.

  • if you are using the File Upload option, it depends on which encoding the HTML file was saved with.
  • if you are using the Direct Input option, it depends on the navigator.

If you don't want the validator to guess, and use UTF-8, you can add the following line

<meta charset="UTF-8">

inside the the head element.

like image 124
federico-t Avatar answered Oct 07 '22 00:10

federico-t