Author

HTML Knowledge Base

I wrote few articles about WordPress, about WooCommerce, PHP etc. But where are the basics? With this entry I would like to start a new series – articles about HTML, which is not as obvious as it seems. Important: we are talking about HTML5 here. We don’t need XHTML or HTML4 anymore. And this is so good…

The global structure of an HTML document

Document Type

Document type should be the first element passed to the browser, after headers. Browser has to know, what we are passing to it. To use HTML5 and this is the only situation we discuss here, use:
<!doctype html>

The HTML element

As you probably know, most of the HTML documents starts with <html> and ends up with </html> tags. It’s so obvious! Or is it?

To be honest, the <html> tag is… optional! Just like it’s closing tag. Due to the normal readability of the document, however, I encourage you to leave these tags. If you use <html tag, then you must use “lang” attribute with it, to set the main language of the document. You may also add class attribute. Adding an ID is useless, because we should have only one element of this type.

Example:
<html class="php-article" lang="en">

Head and body

The next elements are <head> and <body> tags. One of them (!) is optional. What does it mean? If you add a <body> tag, you can skip <head>. If you add <head>, you can skip <body>. As above, for readability, I recommend using both of these tags.

Leave a Reply

Your email address will not be published. Required fields are marked *