The basic structure for all HTML documents is simple and should include the following minimum elements or tags:
- <html> - The main container for HTML pages
- <head> - The container for page header information
- <title> - The title of the page
- <body> - The main body of the page
Remember that before an opening <html> tag, an XHTML document can contain the optional XML declaration, and it should always contain a DOCTYPE declaration indicating which version of XHTML it uses.
Now we will explain each of these tags one by one. In this tutorial you will find the terms element and tag are used interchangeably.
The <html> Element:
The <html> element is the containing element for the whole HTML document. Each HTML document should have one <html> and each document should end with a closing </html> tag.
Following two elements appear as direct children of an <html> element:
As such, start and end HTML tags enclose all the other HTML tags you use to describe the Web page.
The <head> Element:
The <head> element is just a container for all other header elements. It should be the first thing to appear after the opening <html> tag.
Each <head> element should contain a <title> element indicating the title of the document, although it may also contain any combination of the following elements, in any order:
- The <base> tag is used to create a "base" url for all links on the page. Check HTML Base tag.
- The <style> tag is used to include CSS rules inside the document. Check HTML Style tag.
- The <meta> tag includes information about the document such as keywords and a description, which are particularly helpful for search applications. Check HTML Meta tag.
Following is the example of head tag.
The <title> Element:
You should specify a title for every page that you write inside the <title> element. This element is a child of the <head> element). It is used in several ways:
- It displays at the very top of a browser window.
- It is used as the default name for a bookmark in browsers such as IE and Netscape.
- Its is used by search engines that use its content to help index pages.
Therefore it is important to use a title that really describes the content of your site. The <title> element should contain only the text for the title and it may not contain any other elements.
Here is the example of using title tag.
<head> <title>HTML Basic tags</title> </head>
The <body> Element:
The <body> element appears after the <head> element and contains the part of the Web page that you actually see in the main browser window, which is sometimes referred to as body content.
A <body> element may contain anything from a couple of paragraphs under a heading to more complicated layouts containing forms and tables.
Most of what you will be learning in this and the following five chapters will be written between the opening <body> tag and closing </body> tag.
Here is the example of using body tag.
<body> <p>This is a paragraph tag.</p> </body>
Putting all together:
Now if we will put all these tags together, it will constitute a complete HTML document as follows: