What is the correct way to declare an HTML5 Doctype.

user6573 picture user6573 · Jun 9, 2012 · Viewed 53.5k times · Source

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"> 

Answer

Alex W picture Alex W · Jun 9, 2012

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