HTML <!DOCTYPE> Tag
<!DOCTYPE> defines the document type declaration(DTD).
You must place this in the first line of html document just before the <html> tag. In short, this should be the first statement in the HTML document.
This simply informs the browser about the version of the HTML or XHTML document. There is no content inside this tag and there is no closing tag also.
The <!DOCTYPE> declaration is not case-sensitive but it is better to write it in uppercase.
Most Preferred Syntax:
<!DOCTYPE html>
This is the most used syntax for this declaration. Other types are also listed in the page below.
DOCTYPE Declarations
The HTML 4.01 indicates the <!DOCTYPE> declaration for DTD but you do not require to refer DTD for HTML5.
Overall, you can divide the declarations based on the HTML and XHTML versions –
- HTML 5
- HTML 4.01 Strict
- HTML 4.01 Transitional
- HTML 4.01 Frameset
- XHTML 1.01 Strict
- XHTML 1.01 Transitional
- XHTML 1.01 Frameset
- XHTML 1.1
HTML5
This is the most common declaration. Most of the website designers prefers this declaration. You must have only one declaration in the entire document like below –
<!DOCTYPE html>
HTML 4.01 Strict
This includes all the elements and attributes but does not include the deprecated elements and the elements which comes with the framesets.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 Transitional
It includes all the elements and attributes. This also includes the deprecated elements but this does not allow framesets.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
HTML 4.01 Frameset
It includes all the elements and attributes including the deprecated elements. This also allows framesets.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
XHTML 1.01 Strict
It contains a strict layout of a markup. It includes all the elements and attributes but does not include the deprecated elements. This does not allow framesets.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.01 Transitional
It contains a strict layout of a markup. It includes all the elements(including deprecated elements) and attributes. This does not allow framesets.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.01 Frameset
It contains a strict layout of a markup. It includes all the elements and attributes including the deprecated elements. This also allows framesets.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
XHTML 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Example
<!DOCTYPE html> <html> <body> <h2>Example of HTML DOCTYPE declaration</h2> <p>Welcome to TutorialBrain</p> <p>DOCTYPE must be the first line in the HTML document <p> </body> </html>
How Browser will display
NONE
Difference between HTML4.01, XHTML and HTML5
HTML4 | XHTML | HTML5 |
---|---|---|
HTML4 has different versions as HTML 4.01 strict, HTML 4.01 transitional & HTML 4.01 frameset. Each of these has its own DOCTYPE declarations |
XHTML has their declaration as XHTML 1.01 strict, XHTML 1.01 transitional, XHTML 1.01 frameset and XHTML 1.1. Each of these has its own DOCTYPE declarations |
It has only one DOCTYPE declaration for the entier document |
Attributes used
NONE
Always validate your HTML document to check the markup of your document using the W3C Markup Validation Service. You just need to give the URL of the HTML document for validation.
Supporting Browsers
