HTML & CSS Interview Question #3

What does the <!DOCTYPE html> declaration do?

HTML Fundamentals, Structure, Semantics, Links, Images, Tables & Forms Junior Beginner

Quick Interview Answer

The DOCTYPE tells the browser which document type and rendering mode should be used. The HTML5 declaration is simply <!DOCTYPE html>.

Detailed Explanation

The DOCTYPE tells the browser which document type and rendering mode should be used. The HTML5 declaration is simply <!DOCTYPE html>.

Its most important practical purpose is to make modern browsers render the page in standards mode. Omitting or using an inappropriate DOCTYPE can cause a browser to enter quirks mode, where older compatibility behavior may affect layout.

Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Standards Mode Page</title>
</head>
<body>
    <p>Modern HTML document.</p>
</body>
</html>