Head and Body tags
The head and body tags are essential in HTML and XHTML. You insert them right after your DOCTYPE Declaration and html tag (seen later in this page). Body tags must be opened and closed. (Note that most HTML tags need an ending tag. There are exceptions and we will cover them later in the tutorial). Here's an example of the most simple way of including your head and body tags:
|
<html> <head> </head> <body> </body> </html> |
In this head and body tags example, you can see that both tags were opened (<TAG>) and closed (</TAG>)
You probably also noticed the html tag I included right before the head and body tags that closes at the end. Every HTML and XHTML page must have those. the </html> tag must be the very last line of your website.
The head tag
The information that you will include in the html head tag will not be displayed to the user except for the <title> tag. Here are the different head tags:
The title tag
Altho not necessary (but very recommended) in HTML, you need to have this in XHTML. The title contained in this tag will be displayed at the top of the browser. The search engines look at the title in very important way when determining which pages to display first so make your title relevent to the content of the page and put your most important keywords at the beginning of the title. Limit the title lengh at less than 50 characters including spaces so it fits in most browsers. Note that you can only put plain text in the title tag. You cannot put any links of pictures.
Here's an example of a good and clean title:
|
<html> <head> <title>Counter-strike - Get better at PC FPS gaming with our Counter-strike guide</title> </head> <body> </body> </html> |
The body tag
This tag is essential in HTML and XHTML. The head and body tags follow each other in your HTML page. All the content of your page must be included between the opening and closing body tags.
You can specify the width of your page right in the body tag. You can also do this with CSS but since this is a HTML guide, i'll explain it. If you want your page to have a width of 800px, your opening body tag will look like this: <body width="800px">
Here's an example of the head and body tags in action. We will do a page with a simple title and the word "Hello!" displayed to the browser. The width of the body will be 800px:
|
<html> <head> <title>Head and body tags</title> </head> <body width="800px"> Hello! </body> </html> |
| Back DOCTYPE example | Next HTML text style |