Menu
HTML Fundamentals

<!DOCTYPE html>

The document type declaration that tells browsers to render in HTML5 mode.

1Why DOCTYPE Matters

The <!DOCTYPE html> declaration must be the very first line of every HTML document. It puts the browser in standards mode so your CSS and layout behave predictably.

Example Code
css
<!DOCTYPE html>
<html lang="en">
  <head><title>OK</title></head>
  <body>...</body>
</html>

2Put the element in context

The modern HTML doctype asks the browser to use standards mode. It is a declaration rather than an ordinary element with a closing tag. Keep it at the start of a normal HTML document so that layout does not fall into a legacy compatibility mode.

3Practice with a small page

Create two local copies of a simple document and inspect document.compatMode in the console. Keep the modern doctype in your real file. Do not copy a long historical declaration into a new page merely because it appears in an old example.

Finished reading?

Mark this topic as complete to track progress.