HTML Doctype
Doctype is the first element in the source code of a web page and should be at the top of every HTML document, even before the actual code. Unfortunately, the element is often forgotten and many webmasters don't know what function it has at all. Furthermore, the importance of this element is often underestimated. In the following, we will, therefore, explain what function the doctype element has and why it is so important for the correct display of your website.
Contents
Definition
Doctype is not a classic HTML element. Rather, the doctype element specifies which type of document the browser should expect. Current standards stipulate that the element must be present in the source code of every web document. If the doctype element is missing, it is, therefore, an error, even if the document can still be displayed correctly under certain circumstances. Tools for checking source code also display an error if the doctype element is missing in an HTML document.
Where is doctype used?
Doctype must always be the first element of a web page. This means that it is placed in HTML code before the actual mark-up code and thus before the HTML tag. In addition, make sure that the element is present in the source code of each individual subpage. The sole use on the homepage, for example, is not sufficient.
Doctype is further used in XML documents and SVG graphics.
What different doctypes are there?
Especially in earlier versions of HTML as well as for XHTML 1.01 and 1.1 doctypes were very long and complicated. They often had to be copied and pasted into the source code of a document even by experienced webmasters. In all classic versions of the mark-up language before HTML5, the following doctypes had to be used:
HTML 4.01 Strict:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Strict refers to a code that is very precise and strict - comparable to XHTML. Here all elements must always be closed.
HTML 4.01 Transitional:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "http://www.w3.org/TR/html4/loose.dtd">
Transitional, on the other hand, refers to a slightly more tolerant source code. This variant is more comparable with today's HTML5 and not as strict with the mark-up as it is with Strict.
Since HTML4 and previous versions are based on SGML, the correct DTD (Document Type Definition) must be specified in the doctype element for these versions. They describe the rules and elements as well as various other properties used in the code of a document. SGML stands for Standard Generalized Markup Language and describes an obsolete predecessor of HTML. Since the introduction of HTML5, source code has no longer been classified as SGML, partly due to compatibility issues.
For XHTML 1.0 and 1.1, the doctype elements look like this:
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 Loose//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-loose.dtd">
XHTML 1.1 Strict:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
As with HTML4, the DTD must also be specified here, since XHTML 1 and 1.1 are also based on SGML. Browsers are therefore dependent on the appropriate instructions and information to enable a correct display of a website. Strict and Transitional have the same meaning here as in HTML 4.0 and HTML 4.1 and denote the rules that apply to the markup in the source code of the document.
A big change regarding the doctype element has finally occurred with the introduction of HTML 5. Unlike its predecessors, it is no longer based on SGML. In addition, the use of the doctype element has been made less complicated. In HTML5, the use of the doctype element is therefore intended as follows:
<!DOCTYPE html>
No further rules or links are required here. The element can easily be used as specified above. This gives browsers all the information they need to display a website correctly. With HTML5 you, therefore, have one less thing to worry about when creating HTML pages.
Which problems can arise if the doctype element is missing?
If the element is not included in the source code of the web page, it can cause errors. In most cases, however, it will still be displayed correctly. This is especially true if only general code is written in HTML5. Especially if a web page is written in other versions of the mark-up language or uses certain functions that have to be defined by the element in advance, display errors or unexpected problems can occur.
HTML Doctype Checker
Check the doctype declaration in the HTML Code of your web page
Conclusion and summary
The doctype element is a necessary and important part of the source code of any website. It is placed right at the beginning, even before the actual code starts, and should not be forgotten under any circumstances. For HTML5, the doctype element has been simplified significantly. For all other versions of the mark-up language, however, it still has to be used in the correct form. The doctype element contains important information for web browsers which helps to display a web page correctly. According to current standards, the absence of the doctype element is an error and is also characterized as such by appropriate tools for checking the source code of a document.
In summary: HTML Doctype FAQs
What is doctype in HTML?
The doctype declaration tells a browser what kind of document it should expect.
Is doctype an HTML tag?
No, the doctype declaration is no HTML tag. It just offers information to web browsers.
Where do you place the doctype element?
The doctype information has to be placed in the HTML code of your website. It should be the first thing in your code, even before the HTML tag.
Should you include the doctype on every page?
Yes. Every page needs its own doctype declaration.
Do you necessarily need the doctype element for your web pages?
Not necessarily. Your content might still be displayed correctly, even if you do not include the doctype information. However, it is strongly recommended to include the doctype on every page.
Related links
About the author |
The Seobility Wiki team consists of seasoned SEOs, digital marketing professionals, and business experts with combined hands-on experience in SEO, online marketing and web development. All our articles went through a multi-level editorial process to provide you with the best possible quality and truly helpful information. Learn more about the people behind the Seobility Wiki. |