What’s HTML Doctype?
The HTML document type declaration (DOCTYPE), is the first line of code required in every HTML or XHTML document.
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
Difference Between Absolute and Relative References in HTML
A relative reference does not specify the complete path to a web page. It specifies only the name...
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
1 |
<! DOCTYPE html> |
1 |
<! DOCTYPE html> |
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
1 2 3 4 5 6 7 8 9 10 |
<!DOCTYPE html> <html> <head> <title>Title of document</title> </head> <body> ...main content of document goes here... </body> </html> |
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:
1 |
<DOCTYPE html> |
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
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
DOCTYPE Declaration of HTML 1.1
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
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.
1 2 3 4 5 |
<DOCTYPE html> <docTYPE html> <DOCtype html> <dOcType html> <doCTypE html> |
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.
1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
You May Also Like…
Block And Inline Level Tags in HTML
Block elements start on a new line and end with a carriage return. That's, immediately after ending on a horizontal...
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
HTML offers a range of elements for formatting text. HTML formatting tags include : <b> - Bold text...
Recent Comments