Select Page

What’s HTML Doctype?


The HTML document type declaration (DOCTYPE), is the first line of code required in every HTML or XHTML document.


nanadwumor

May 27, 2023
html doctypes

Share this article

The HTML document type declaration (DOCTYPE), is the first line of code required in every HTML or XHTML document.

DOCTYPE is short for Document Type. The DOCTYPE tells the browser the version of HTML the page was written in to help the browser understand and interpret the page very well.

Join other Subscribers on our YouTube channel and enjoy daily pogramming tutorials.

Recommended


The DOCTYPE statement is the first line of code in the html document. It comes first even before you type the <html> tag.

Common Syntax of DOCTYPE for HTML5

Let’s look at a typical html document that demonstrates the Doctype as the first line of code.

Program demonstrates DOCTYPE as first line of code

Other types of HTML

Html5 is a modern form of html. There exists other types. Examples include HTML 4.01, and XHTML

Doctype declarations for other forms of html

The DOCTYPE declarative statement for HTML5 is very simple. This is:

But this wasn’t always the case. Former forms of HTML had very horrible and weird declarations. Let’s look at some example.

DOCTYPE Declaration of HTML 4.01

DOCTYPE Declaration of HTML 1.1

Why doesn’t HTML 5 have Document Type definition (DTD)?

HTML5 is not based on SGML (Standard Generalized Markup Language), and therefore does not require a reference to a DTD (Document Type Definition).

Why do we have different DOCTYPE Declarations?

In the early years of HTML and web development, there were no standard web protocols. Web browsers were made without recourse to any fundamental concepts. Manufacturers could build any feature into their product as they deemed fit.

This made it difficult for a single website to be rendered the same in different browsers. Web developers had to choose a particular browser and develop their websites to be properly rendered in. That’s, a website that is rendered well in Chrome may not do same in Firefox.

In order to remedy this situation, the W3C (World Wide Web Consortium) wrote a set of web protocols to standardize web development. This was to ensure that all websites render well in all browsers.

Unfortunately, the changes implemented by the standards differed from some existing practices. These implied that sticking to the new standards would break existing non-compliant websites.

A smart way out was for a website or page to inform a browser which form of the HTML it was developed in. This resulted in the different DOCTYPE Declarations.

So a DOCTYPE statement like : <!DOCTYPE html> tells the browser that the page should be rendered as an HTML 5 document.

The DOCTYPE statement is not case sensitive

The DOCTYPE statement is not case sensitive. That’s, we can combine capital and small letters and all will be fine.

All the following declarations are correct.

HTML5 is backward compatible with other versions

The previous versions of HTML specified the version number in their DOCTYPE declarations, such as the DOCTYPE for XHTML 1.0 Strict is:

HTML5 does not include the version in the DOCTYPE. This allows HTML5 to be backward compatible in terms of syntax with the other versions. 

Let’s assume that you have a website that was built in HTML 4.0, but you want to transition it to HTML5.

All there’s to do is to change DOCTYPE from HTML 4.0 to HTML5. All modern browsers recognize the shortened DOCTYPE and render in strict standards mode.


Share this article


You May Also Like…

Selecting a browser for HTML5 development
Selecting a browser for HTML5 development

Google's Chrome browser is simple to use and has the most up-to-date HTML5 features making it easier for developers....

Top 10 HTML5 formatting tags
Top 10 HTML5 formatting tags

HTML offers a range of elements for formatting text. HTML formatting tags include : <b> - Bold text...