The <!doctype>
is not an HTML tag but a way to tell the browser about what document type or specification to adhere to. In case it is not present, the browser goes into quirks mode, applying its own version of html interpretation and so possibly some HTML5 tags may or may not work. So, it is necessary that an HTML5 document must begin with a <!doctype html>
declaration.
Element Type | — |
---|---|
Self Closing | True |
Positioning | Begining of the document |
Every HTML version has a unique <doctype>
declaration, the structure of each of the versions and their respective <!doctype>
declration is given below.
Syntax
List of HTML versions and their doctypes declarations
HTML5 Doctype
<!doctype>
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">
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 Frameset
<!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">
Code Example
This is how you use the <!DOCTYPE>
declaration. The example below shows a valid HTML5 Doctype declaration.
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>An HTML Document</title>
</head>
<body>
<h1>This is an HTML Document</h1>
<p>This is a simple paragraph with a <a href="#">link</a></p>
</body>
</html>
The <!doctype>
declaration is case-insensitive, for the fact every HTML tag is, meaning the browser doesn't care if you write it in lowercase, uppercase or mixed case, all are valid as long as they are spelled correctly. But its better to stick to a convention for consistency, generally all tags are used in lowercase except for <!doctype>
as in the example above.
Tag-Specific Attributes
This tag just instructs the browser about the document type, it does not have any attribute.
Global Attributes
No supported global attributes
Events Attributes
No supported events attributes
Accessibility Guidelines
No such applicable guidelines for this tag.
Browser Support
The <!doctype>
tag is well supported in all major browsers.
Syntax | Chrome | Firefox | Edge | Safari | Opera | Internet Explorer |
---|---|---|---|---|---|---|
<!DOCTYPE> |