Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 html-tag and DOCTYPE

From what I've read, the correct way to start an HTML5 page is:

<!DOCTYPE html>
<html>

With nothing more in those lines. Is this true? (I'm asking because Visual Studio has more than that.)

(Also, I'm wondering if HTML5 is really the current standard or should I be using XHTML5 or some other version.)

like image 629
ispiro Avatar asked Nov 29 '12 16:11

ispiro


2 Answers

According to the HTML living standard and the W3C spec, the doctype is the required preamble but required for legacy reasons. I quote:

  1. A string that is an ASCII case-insensitive match for the string "<!DOCTYPE".
  2. One or more space characters.
  3. A string that is an ASCII case-insensitive match for the string "html".
  4. Optionally, a DOCTYPE legacy string or an obsolete permitted DOCTYPE string (defined below).
  5. Zero or more space characters.
  6. A U+003E GREATER-THAN SIGN character (>).

In other words, <!DOCTYPE html>, case-insensitively.

And <html></html> for a valid document

(Also, I'm wondering if HTML5 is really the current standard or should I be using XHTML5 or some other version.)

It is not the current standard IMHO because it is not finished yet. But this article explains very well 10 reasons for using it now.

like image 100
ElderMael Avatar answered Sep 18 '22 23:09

ElderMael


Mostly yes. But the HTML5 spec for the <html> element says

Authors are encouraged to specify a lang attribute on the root html element, giving the document's language. This aids speech synthesis tools to determine what pronunciations to use, translation tools to determine what rules to use, and so forth.

so better, for a page whose content is in American English, would be

<!DOCTYPE html>
<html lang="en-us">

Also if you are using XHTML5 served as application/xhtml+xml you will need to add the namespace, and also the XML equivalent of the lang attribute making it:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-us" xml:lang="en-us">
like image 43
Alohci Avatar answered Sep 18 '22 23:09

Alohci