0
0
HTMLmarkup~5 mins

DOCTYPE declaration in HTML

Choose your learning style9 modes available
Introduction

The DOCTYPE declaration tells the web browser which version of HTML the page uses. This helps the browser show the page correctly.

Every time you create a new HTML page to make sure browsers understand it.
When you want your webpage to follow modern web standards.
To avoid browsers guessing the HTML version and possibly showing errors.
When you want consistent display across different browsers and devices.
Syntax
HTML
<!DOCTYPE html>

This declaration is placed at the very top of your HTML file.

It is not case sensitive but usually written in uppercase for clarity.

Examples
This is the standard DOCTYPE for HTML5, the current version of HTML.
HTML
<!DOCTYPE html>
This is an older DOCTYPE for HTML 4.01 Strict, rarely used today.
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Sample Program

This is a simple HTML5 page starting with the DOCTYPE declaration. It helps browsers know to use modern HTML rules.

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sample DOCTYPE</title>
</head>
<body>
  <h1>Hello, world!</h1>
  <p>This page uses the HTML5 DOCTYPE declaration.</p>
</body>
</html>
OutputSuccess
Important Notes

Always put the DOCTYPE declaration as the very first line in your HTML file.

Without it, browsers may switch to 'quirks mode' and display your page incorrectly.

Summary

The DOCTYPE declaration tells browsers which HTML version to use.

Use <!DOCTYPE html> for all modern HTML pages.

It must be the first line in your HTML document.