Skip to Content

HTML DOCTYPE Declaration: Following Web Standards

The DOCTYPE declaration is the first entry that should appear at the top of all HTML documents to meet current web standards.

What is a DOCTYPE in HTML?

DOCTYPE is a documentation type declaration that tells the browser which version of HTML a web page is written in. It's the first line of code required for any HTML or XHTML document and helps different browsers parse the web page the same way.

The History of DOCTYPE

Back in the younger days of the internet, web standards were not always agreed on by different vendors. Browser vendors would create their own web standards and features the way they wanted versus following a set of written guidelines.

Enter the W3C (World Wide Web Consortium), the primary international standards organization responsible for creating a set of web standards that browser vendors and web developers were instructed to adhere to.

Of course, implementing these changes into web page documents caused issues where web standards and best practices went ignored. In response, the browser vendors began programming rendering modes into their browsers to address the issue.

The three different rendering modes are:

  • Full standards mode: Renders a web page according to the W3C web standards.
  • Quirks mode: Renders a web page without standards in place.
  • Almost standards mode: Almost all standard features applied, with some support for a small number of quirks.

Today, web standards are fully implemented for HTML5 in all major browsers, making it much easier to provide a declaration type and parse web page content.

Do I Need the DOCTYPE Declaration?

Yes. Even though modern browsers have a much easier time parsing web page content, the DOCTYPE declaration is still required in all HTML documents so browsers can interpret the document's contents correctly.

Usage

Remember, the DOCTYPE declaration is required at the top of every HTML page. The declaration for a modern HTML5 document looks like this:

<!DOCTYPE html>

Before HTML5, longer declaration types were a requirement to parse certain web pages correctly. Although these methods are somewhat outdated at this point, they're still worth mentioning and knowing:

  • Strict DTD: Used in web pages that exclude elements the W3C expects to phase out as CSS support increases.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  • Transitional DTD: Used in web pages that include elements the W3C expects to phase out as CSS support increases.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  • Frameset DTD: Used for web pages containing frames.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

XHTML Declaration

XHTML, Extensible HyperText Markup Language, is a more strict version of a combination of the XML and HTML languages, requiring a more organized approach to coding formats.

The XHTML DOCTYPE declaration can be defined like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Conclusion

Setting the DOCTYPE declaration in your HTML code is important, but it's only the first step. For a more comprehensive look at how HTML pages are structured and to really get your feet wet, check out our basic guide to HTML.

Created: August 26, 2022

Comments

There are no comments yet. Start the conversation!

Add A Comment

Comment Etiquette: Wrap code in a <code> and </code>. Please keep comments on-topic, do not post spam, keep the conversation constructive, and be nice to each other.