Head Element and Body Tag in HTML

head element and body tag

HTML <HEAD> Element

The<head> element is just a container for all other header elements. It is the first thing to appear after the opening of the <html> tag.

Here the scriptwriter can show decorative scripts like CSS code or JavaScript code.

The <head> tag has its closing tag also which ends above the start of the <body> tag, and each and every <head> tag contains the <title> element to indicate the title of the web page on the title bar.

Inside the <head> element there we can use some more elements which are the following…

  • <base> – This transforms the relative URL into a full absolute URL. This element allows you to specify a base URL for a page. 
  • <object> – The website includes images, javascript objects, flash animations, mp3 files,  QuickTime movies, and other types of files on the page. 
  • <link> – The link element is used to link external files, such as style sheets or javascript files.
  • <style> – The style element includes the CSS rules. 
  • <script> – The script element include the javascript code and rules.
  • <meta> – Which includes the information about the document such as keywords and description which are particularly helpful for the search. This will web page for better search engine optimization.

HTML Body Tag

The tags used to indicate the start and end of the main body of textual information are:

<body>//starting body tag.
.
.
.
</body>//closing of body tag.

Page defaults like background color, text color, font size, font-weight, and so on can be specified as attributes of the <body> tag. The attributes of the <body> tag are given.

  • Bgcolor: Change the default background color, to whatever color is specified on it. We can define color as a hexadecimal value (#fff) or color name. (white, red, blue, etc).
  • Background: Specifies the name of a picture file like a Gif file that will be used as the background of the document.
  • Text: Change the body text color from its default value to the color specified by this attribute.
Parameter name Description
BACKGROUND Specifies an image to repeat as the background of the page
BGCOLOR Specifies a color to use as the background for the page
TEXT Specifies the color of use as the default color for the text
LINK Specifies the color to use for the link that has not been clicked
VLINK Specifies the color to use for the link that has been clicked

Example 1,

<body bgcolor='#ff0000'> or <body bgcolor='red'>

Example 2,

<body background='picutre_name.jpg'>

While changing the background as an image, the image file should be present in the current working directory. If not relative path should be specified to where the image file exists.

Example 3,

<body text='black'> or <body text='#000000'>