HTML Document Structure: How to Create DOCTYPE in HTML

html doctype

The DOCTYPE ensures that your HTML is readable by browsers and ensures that pages follow modern standards.

Understand the DOCTYPE in HTML

The DOCTYPE is not an HTML tag. You place it at the top of your document. It tells the browser which HTML rules to use. This activates standards mode. The browsers switch to quirks mode without it, and that causes layout and style problems.

Modern browsers do not require a full DTD. They rely on the DOCTYPE to parse your page correctly. A wrong DOCTYPE makes browsers show the page differently. This causes problems with layout and style.

Older HTML versions used long DTDs based on SGML. These DTDs validated your HTML against rules. There were three main types:

  • Strict: Enforced all rules. No deprecated tags like <font>.
  • Transitional: Allowed some old tags.
  • Frameset: Used when pages had frames.

DOCTYPE Syntax by Version in HTML

HTML 4.01/XHTML 1.x

These use a DTD that links to the W3C site.

HTML 4.01 Strict:

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

HTML 4.01 Transitional:

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

HTML 4.01 Frameset:

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

XHTML 1.0 Strict:

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

These DTDs control what tags and attributes you can use. They also define how the browser handles errors.

HTML5

HTML5 DOCTYPE:

<!DOCTYPE html>

This works the same in all browsers. You use it for every HTML5 page. It does not point to a DTD file.

Examples

Basic HTML5 Page

<!DOCTYPE html>
<html>
  <head>
    <title>The Title of Page</title>
  </head>
  <body>
    <p>This is a modern HTML5 page.</p>
  </body>
</html>

This uses the HTML5 DOCTYPE. It starts the page in standards mode and avoids quirks mode so CSS and layout behave as expected.

HTML 4.01 Strict for Clean Code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>The Strict Page</title>
</head>
<body>
  <p>This version skips old tags and follows all the HTML rules.</p>
</body>
</html>

This page uses the strict DTD, which disallows presentational tags like and suits clean, rule-based projects.

XHTML 1.0 Transitional for Mixed Content

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>The XHTML Transitional</title>
</head>
<body>
  <p>This format lets you use old HTML rules and new XHTML rules together.</p>
</body>
</html>

This blends HTML and XML. The xmlns shows that it follows XHTML. You can use older tags, but the syntax must be exact.

Frameset DOCTYPE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
  "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
  <title>The Frameset Web Page</title>
</head>
<frameset cols="50%,50%">
  <frame src="left.html">
  <frame src="right.html">
</frameset>
</html>

This uses a frameset. It splits the page into frames. While outdated, some legacy systems still rely on it. You cannot use <body> with <frameset>.

Wrapping Up

In this article, you learned what the HTML DOCTYPE does and why it matters. You also saw how it changed over time from complex DTDs to the simple HTML5 form.

Here is a quick recap:

  • The DOCTYPE tells browsers how to read your page.
  • It keeps your page in standards mode, not quirks mode.
  • HTML5 uses <!DOCTYPE html> with no DTD file.
  • Older versions use long DTD links that define valid tags and rules.
  • Each version suits a different purpose—modern, strict, mixed, or framed layouts.

FAQs

What is <!DOCTYPE html> and why is it important?

The <!DOCTYPE html> declaration tells the browser which version of HTML the page is written in. It’s essential because it triggers standards mode in browsers, ensuring consistent rendering across different platforms. In HTML5, the declaration is simple and case-insensitive:
<!DOCTYPE html>
Without it, browsers may switch to quirks mode, which can lead to inconsistent layout and CSS behavior.

Is <!DOCTYPE html> required in HTML5?

Yes, the <!DOCTYPE html> declaration is required even in HTML5. Although HTML5 does not rely on a Document Type Definition (DTD), the declaration is still necessary to ensure the document is interpreted in standards mode. Here's how it should be declared:
<!DOCTYPE html>
Using it correctly at the beginning of the HTML document helps prevent rendering issues across modern browsers.

What happens if you omit the <!DOCTYPE> declaration?

If you omit the <!DOCTYPE> declaration, most browsers will enter quirks mode. In this mode, browsers emulate non-standard behavior from older versions to support legacy pages. This can result in:
  • Broken layouts
  • Inconsistent CSS rendering
  • Unpredictable behavior in JavaScript
To avoid these issues, always start your HTML documents with:
<!DOCTYPE html>

Similar Reads

How to Use sub Tag for Subscript Text in HTML

The sub tag in HTML shows text in subscript form. It places the text slightly below the normal baseline of…

HTML base Tag: How to Set a Base URL for Links and Resources

Use the <base> tag in HTML to set a single base URL or target for all relative links and resources…

HTML Global Attributes Overview

HTML global attributes work on most elements. They do not depend on the tag name. You can use them with…

HTML title Attribute: How it Works with Examples

The HTML title attribute adds extra info to any element. You can use it to show tooltips on hover. What…

HTML object Tag: How to Embed External Objects with Examples

Use the HTML object tag to embed different types of external files into your webpage. It works for videos and…

HTML title Tag: How to Set Web Page Titles

The title tag in HTML shows the page name in the browser tab and helps search engines know the topic.…

HTML abbr Tag: How Abbreviations Work with Examples

The abbr tag refers to an abbreviation in HTML. It helps you save space and improve accessibility. The screen readers…

HTML Footer Tag for Document Footers

The <footer> tag defines a footer section in HTML. It creates a clear endpoint for a page or section. Browsers…

HTML Nav Tag: How to Create Navigation Menus

The nav tag defines a navigation block in HTML. It holds main links to other parts of your site. Search…

HTML Form Tag: How Create User Input Forms

The HTML form tag helps you collect user input on a website. You use the HTML form tag to create…

Previous Article

HTML Form novalidate Attribute: How it Works with Examples

Next Article

PHP array_filter: How to Filter Array Values with Examples

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.