MakeW3web

Doctype declaration

A document type declaration, or DOCTYPE, is an instruction to web browsers about the version of HTML used in an HTML document. This helps the browser render the page correctly by understanding the specific HTML standard being used. DOCTYPE must be the first line of code in an HTML document before the opening `<html>` tag.

Over the years, various versions of HTML have been developed. The DOCTYPE declaration has evolved with these versions. In HTML5, the DOCTYPE declaration has been simplified, and you only need to use the following line:

<!DOCTYPE html>

This line tells the browser that the HTML document is using the HTML5 standard.

Here are some examples of DOCTYPE declarations in older HTML versions:

1. HTML 4.01 Strict:

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

2. HTML 4.01 Transitional:

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

3. XHTML 1.0 Strict:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

4. XHTML 1.0 Transitional:

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

Nowadays, it is recommended to use HTML5 for web development because it is the latest version and has better support for modern browsers.

Example of an HTML5 document with the correct DOCTYPE declaration:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My HTML5 Page</title>
</head>
<body>
    <h1>Welcome to my HTML5 page!</h1>
    <p>This page uses the HTML5 standard.</p>
</body>
</html>

In this example, the `<!DOCTYPE html>` declaration informs the browser that the document is an HTML5 document. The browser will then render the page according to HTML5 rules, ensuring that the page displays correctly.

Was this page helpful?