Reputation: 27633
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.)
Upvotes: 10
Views: 9481
Reputation: 7101
According to the HTML living standard and the W3C spec, the doctype is the required preamble but required for legacy reasons. I quote:
- A string that is an ASCII case-insensitive match for the string
"<!DOCTYPE"
.- One or more space characters.
- A string that is an ASCII case-insensitive match for the string "html".
- Optionally, a DOCTYPE legacy string or an obsolete permitted DOCTYPE string (defined below).
- Zero or more space characters.
- 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.
Upvotes: 11
Reputation: 201518
According to the HTML5 drafts, “A DOCTYPE is a required preamble”. The preamble <!DOCTYPE html>
is recommended, but legacy doctypes are allowed as an alternative, though they “should not be used unless the document is generated from a system that cannot output the shorter string”. The only part that is required in addition to it is the title
element, and even it may be omitted under certain conditions. The <html>
tag is not required.
HTML5 is not a standard. It is not even a W3C recommendation (yet). What you should use depends on what you are doing. It does not really matter which version of HTML you think you are using. What matters is the markup you have and how browsers (and search engines etc.) process it.
Upvotes: 2
Reputation: 82966
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">
Upvotes: 4
Reputation: 2094
Yes it's true. No more complicated doctypes in HTML5. The new standard is simplified and there's only the one you said.
Upvotes: 3