As explained before an HTML
document consists of a head section
and a body section. Now let’s take a
look at some of the tags that appear in each of the section.
Parts of a HTML document
Document head
Some of the
tags permitted in the head section of a document are:
<title>
- there can only be one title for a web page.
<link> -
used when the document is associated with another document
<meta> -
provides information of the content of the document
<object>
-to place various objects
<style>
- information regarding styling a document. This will be covered in a later
section
<script>
-used when dealing with a scripting language such as javascript, PHP, etc
<base> -
specifies the documents base URL
Document body
There are wide
varieties of elements that appear in the body section. Certain elements are
associated with structuring the document and certain elements are associated
with styling. Also HTML elements can be differentiated between “Block elements” and “Inline elements”.
Block elements
Now let’s try out some examples
with block elements.
Example 1:
Now let’s try out some examples with block elements.
Example 2:
Inline Elements
Inline elements don’t have a line break before or after the element. Usually inline element appears within block elements. If inline element appear separately a break tag (“<br>”) is used to make a line break.
Note: when inline elements are not included within block elements then a break tag needs to be added to make line break. <br> tag is a special tag, since it does not have a opening and a closing tag. The break tag can be typed as either “<br>” or <br />. <hr> is another tag that does not have both a opening and a closing tag. It can also be typed as either as “<hr>” or “<hr />” in HTML. <hr> tag creates a horizontal line across the web page.
Attributes
Attributes give more meaning to elements. Attributes are places in the opening tag. The syntax of an attribute is:
<opening_tag attribute=”value”>element content</closing_tag>
Eg: <body bgcolor=”red”>
…………
………….
</body>
Here the bgcolor attribute is placed in the <body> tag. bgcolor is the name of the attribute. The value of the attribute is placed inside double quotes (“”). In this example the value of the bgcolor attribute is red. Though it is not mandatory to place an attribute value within double quotes, it is a good practice to follow.
There are wide varieties of attributes used with elements. Most of the important attributes will be discussed during the course in various sections. In general attributes can be put into five groups. They are universal attributes, language attributes, events, presentational attributes and specialized attributes. Some of the universal and presentational attributes will be discussed in this chapter.
2.5.1 Universal attributes
id attribute
The “id” attribute gives an element a unique identity in the document. The id attribute value must be unique otherwise during rendering the browser will throw an error message. “id” attribute must start with a letter or an underscore and should only contain alphanumeric characters. “id” attribute has replaced the use of the “name” attribute.
Style attribute
This attribute is used to introduce style into a document. But however style sheets are a better method of styling than using this attribute. This attribute is supported by many elements.
Example: