HTML Tutorial - HTML Document








HTML DOCTYPE

The doctype element is unique and in a category of its own.

You are required to begin every HTML document with a doctype element. This element tells the browser that it will be dealing with HTML.

Most browsers will still display your content correctly if you omit the doctype element.

The DTD that was required in HTML4 is obsolete in HTML5

There is only one way to use the doctype element in HTML5, and that is shown in the following.

<!DOCTYPE HTML>

This element tells the browser two things: it is dealing with HTML, and the version of the HTML specification of the content.

There is no end tag for this element. You simply put a single tag at the start of the document.





html Element

The html element, or root element, indicates the start of the HTML.

html element has one head element and one body element.

The following code shows the html element in use.

<!DOCTYPE HTML>
<html>
...content and  elements omitted...
</html>

head Element

The head element contains the metadata for the document.

In HTML, metadata has the information about the content and markup in the document. It cal also include scripts and references to external resources, such as CSS stylesheets.

The title element inside the head element is required; other metadata elements are optional.

The following code shows the head element in use.

Every HTML document should contain a head element and it must contain a title element, as shown in the code.

<!DOCTYPE HTML>
<html>
    <head>
       <title>Hello</title>
    </head>
</html>




Metadata Elements

The metadata elements are not content themselves, but they provide information about the content that follows.

Metadata elements are added to the head element.

body Element

The body element encapsulates the content of an HTML document ,while the head element encapsulates metadata and document information.

The body element always follows the head element so that it is the second child of the html element.

The body element's attributes from HTML4: alink, background, bgcolor, link, margintop, marginbottom, marginleft, marginrightm, marginwidth, text, and vlink, are obsolete.

The effect that these attributes had can be achieved with CSS.

The following code shows the body element in use.

<!DOCTYPE HTML>
<html>
    <head>
       <title>Example</title>
    </head>
<body>
    <p>This is a test</p>
    <a href="http://java2s.com">Visit  java2s.com</a>
</body><!--from   ww  w . jav  a 2  s. c  o  m-->
</html>

Click to view the demo

One p element and one a element are added to the body element.