The doctype is the first row in every HTML document, and we use it automatically. This one line tells the browser what to expect and how to process the information.
Like a lot of things in web development today, it now has a more natural syntax. Back in the day when the HTML 4.01 and XHTML 1.0 were the deal, you had to be possessed if you wanted to type it from memory.
How Looks an HTML 5 Doctype Declaration
Declaring the proper doctype in HTML 5 is simple, just two worlds:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> </body> </html>
Although it is short we still have to pay attention to some details:
- We always have to declare a doctype in our HTML files.
- It must be the first element before the <html> tag.
- The <!DOCTYPE> declarations isn’t case sensitive.
- The doctype is not an HTML tag, and it doesn’t have a closing tag.
How We Declared the Doctype Previously
With HTML 4.01 and XHTML 1.0, we had a lot of different declaration based on the type. Also, we had to set DTD because these were based on SGML.
SGML is an old markup language, which was an ISO standard from 1986. It provided a syntax for HTML, which was the most popular use of it.
The DTD is a document type definition. It was needed because there was more than one HTML 4 document type (strict, transitional, frameset).
<!-- A strict HTML 4.01 declaration. --> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- A strict XHTML 1.0 declaration. --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">