What is the correct way to declare an HTML5 Doctype.

HtmlDoctype

Html Problem Overview


What is the correct way to use start tag when creating with HTML5

IE: HTML 4 Strict is like this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

Html Solutions


Solution 1 - Html

The standard has been simplified because the previous doctypes were too cryptic. The new doctype is simply <!DOCTYPE html> . You may wonder why it is not <!DOCTYPE html5> but it is simply because it is just an update to the standard of HTML and not a new version of anything. As you can see below, all elements can now have a language attribute.

> The <html> element is the root element of a document. Every document > must begin with this element, and it must contain both the <head> and > <body> elements. > > It is considered good practice to specify the primary language of the > document on this element using the lang attribute.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Hello World</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>
            Jamie was here.
        </p>
    </body>
</html>

More info: https://dev.w3.org/html5/html-author/#doctype-declaration

Solution 2 - Html

you just use

<!DOCTYPE html> 
<html>
</html>

Solution 3 - Html

First of all, html5 doctype is not case sensitive.

Either one of these three will work:

  1. <!DOCTYPE html>

  2. <!DOCTYPE HTML>

  3. <!doctype html>

You can check the validity here.

Solution 4 - Html

It's as simple as

 <!DOCTYPE html>

Solution 5 - Html

According to the WWW Consortium, the organization responsible setting current web standards, no one has answered this correctly. The current standard for language declaration is > Always use a language attribute on the html tag to declare the default > language of the text in the page. When the page contains content in another > language, add a language attribute to an element surrounding that content. > Use the lang attribute for pages served as HTML, and the xml:lang attribute > for pages served as XML. For XHTML 1.x and HTML5 polyglot documents, use both > together.
W3C HTML Language Tag Page

Here is the answer regarding DOCTYPE declaration

> Use the following markup as a template to create a new HTML document using a > proper Doctype declaration. See the list below if you wish to use another DTD.
W3C DOCTYPE Standards

<!DOCTYPE html>
<html>

<head>
    <title>An HTML standard template</title>
    <meta charset="utf-8"  />
</head>

<body>
     <p>… Your HTML content here …</p>
</body>
</html>

Hope this helps.

Solution 6 - Html

You use...

<!DOCTYPE html> 

followed by your HTML tag etc..

Solution 7 - Html

You only need this:

<!DOCTYPE html> 
<html>
...

There are several points here. This is supported by all browsers, even old ones like IE6/IE7. All browsers actually nee "html" part from doctype declaration to jump into standards mode.

Solution 8 - Html

<!-- simplified doctype works for all previous versions of HTML as well -->
<!doctype html>

Learning Resource:

Solution 9 - Html

The start tag <html> is optional in HTML5, as in HTML 4.01. If used, it must be the first tag. It has different optional attributes: the global attributes of HTML5, and the special manifest attribute. The most common useful attribute in the <html> tag is the lang attribute.

(The doctype declaration is something quite different, and not a tag at all.)

Solution 10 - Html

The clearest most definitive answer of what the standard says seems to be for HTML 5.3 at:

http://w3c.github.io/html/syntax.html#the-doctype

Note especially the list-items 1 and 3 which specify that the doctype-statement is case-insensitive. Also note the number of spaces inside the statement can vary.

And note the clause "A DOCTYPE is a required preamble."

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser6573View Question on Stackoverflow
Solution 1 - HtmlAlex WView Answer on Stackoverflow
Solution 2 - HtmlKirill FuchsView Answer on Stackoverflow
Solution 3 - HtmlasmmahmudView Answer on Stackoverflow
Solution 4 - Htmlgion_13View Answer on Stackoverflow
Solution 5 - HtmlAndrew SmallwoodView Answer on Stackoverflow
Solution 6 - HtmlMike SavView Answer on Stackoverflow
Solution 7 - HtmliosebView Answer on Stackoverflow
Solution 8 - HtmlSarfrazView Answer on Stackoverflow
Solution 9 - HtmlJukka K. KorpelaView Answer on Stackoverflow
Solution 10 - HtmlPanu LogicView Answer on Stackoverflow