Attributes are the additional feature can be added to a tag to apply or enhance the appearance of different parts of a web page. Attributes are written immediately after an opening tag is separated by tab or space. The closing tag does not contain any attributes or its value.
An attribute is followed by an equal to sign (=) and a value associated with that attribute. The value of an attribute is generally written within quotes. However the quote is not required if the value is a single word or digit.
Attributes are used to
- Define data source or destination.
- Specify URL (Uniform Resource Locator)
- Specify the characteristics of the text to which a tag is applied.
Syntax to use an attribute is
<Tag Name Attribute = "Value"
For ex
<BODY BGCOLOR = "yellow"
In above example BGCOLOR is an attribute of tag BODY and its value is yellow. It will effect the background color of web page (body section) as yellow.
Here is a list of attributes generally used with <BODY> tag. The value of an attributes should not exceed 1024 characters.
- BGCOLOR
- TEXT
- ALIGN
- BACKGROUND
- LINK
- ALINK
- VLINK
- LEFTMARGIN
- TOPMARGIN
As discussed above BGCOLOR attributes (Background color) is used with BODY tag. It is followed by "=" sign with name of the color like 'red'. It is used to set or change the background color of the body text in a web page.The syntax is
<BODY BGCOLOR="Value">
TEXT Attribute
This attribute is used to set the color of the body text in a web page. This attribute is also followed by an equal sign and name of the color, like
<BODY TEXT = "RED">
or
<BODY TEXT = "#FF0000">
#FF0000 is the RGB value (code) of red color.
Following is the table to show the codes of different color.
COLOUR NAME HEX RGB Value
Aqua #00FFFF
Blue #0000FF
Green #008000
Maroon #800000
Red #FF0000
White #FFFFFF
Black #000000
Grey #808080
Lime #00FF00
Purple #800080
Silver #C0C0C0
Yellow #FFFF00
ALIGN Attribute
This attribute is used to align the text in left, right or center.
The syntax is
<BODY> ALIGN = "CENTER"
It will display the text in web page in center not by left aligned which is by default alignment of the text in a web page.
Now try the following codes in notepad :
<html>
<head>
<title> MY FIRST WEBPAGE </title>
</head>
<BODY BGCOLOR = "YELLOW" TEXT = "RED" ALIGN = "CENTER">
Welcome to my first web page.
</body>
</html>
Try above program yourself
Output |
BACKGROUND Attribute
This attribute is used to set the background image of the web page. Background image can be textual or image.
Background attribute is used when an organisation want its company's Logo in the background of the web page or a tourist or similar companies want the picture of the destination place in the background. Any picture that is available in .bmp, .gif, .jpeg file can be used as background image. The syntax is
<BODY BACKGROUND = "Name of the picture with its path">
<BODY BACKGROUND = "C:\Users\asd\Desktop\NATURE.jpg>
Now try the following coding in notepad :
<html>
<head>
<title> MY FIRST WEBPAGE </title>
</head>
<BODY BACKGROUND = "C:\Users\asd\Desktop\NATURE.jpg" TEXT = "RED" ALIGN = "RIGHT">
Welcome to my first web page.
</body>
</html>
In Browser |
Now see in web browser the picture "NATURE.jpg" appears as background and text is in red and aligned to the right.
(you can put the url of any image available with permission to use on web.)
Output |
LINK, ALINK and VLINK Attributes
Usually we see three types of link in a web page, these are
LINK - This link has not yet been visited. By default it appears in blue colour.
ALINK (Active Link) - This link is currently in use and by default it appears in red colour.
VLINK (Visited Link) - This link was visited last and by default appears in purple.
Syntax to change the colour of these links are:
<BODY LINK = "yellow" VLINK = "maroon" ALINK = "green">
Link, Alink and Vlink are not supported in HTML5.
LEFTMARGIN and TOPMARGIN Attributes
Margin refers to the blank space from the edge of the page. Leftmargin is the blank space from left edge of a web page and Topmargin is the blank space from top edge of a web page.
Syntax to set the margins are
<BODY LEFTMARGIN = "80" TOPMARGIN = "60">
The above coding leave the blank space from left 80 pixels and from top 60 pixels.
Try the following codes in text editor
<html>
<head>
<title> MY FIRST WEBPAGE </title>
</head>
<BODY LEFTMARGIN = "80" TOPMARGIN = "60">
Welcome to my first web page.
</body>
</html>
See in web browser text appears with 80 pixels margin from left and 60 pixels margin from top.