Document Structure
Most HTML documents share a common structure. Let’s look at an example and then we will explain, as best as we can, what each part is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>This goes in the browser's title bar</title> <link href="some-style.css" media="screen" rel="stylesheet" type="text/css" /> </head> <body> </body> </html> |
An HTML document begins with a declaration of its type. This is the DOCTYPE
line you see in our example. For more information about document types we have created a [separate chapter][html/doctype].
Next in our example, we see the opening html
tag with a few attributes specifying the language and the xml namespace.
The head
element can contain several different elements but most of them are not content elements with the exception of title
which can be considered content since it is displayed in places such as the browser’s title bar and tab bar and the system task bar. In the head
section we also see meta
elements, references to CSS and JavaScript.
Finally, all content belongs in the body
section of the document but don’t forget the closing </body>
and </html>
tags.