Basic HTML Tutorial

BHP HTML Basics - Adding Color


Attributes in the Body tag
In the previous page, we saw how attributes could be used to control the position of text on our web page by using the ALIGN attribute in the <P> tag. In this page, we will learn how to use attributes in the <BODY> tag to set the color of the page background and the color of the text.
The attribute to set the background color of the web page is BGCOLOR and the attribute to set the text color is another easy to remember one, TEXT. The attributes are added to the <BODY> tag in the same way that the ALIGN attribute was added to the <P> tag.
But how do we tell the browser what color to use? We do this by assigning a value to the attribute for the background color and for the text. There are two different ways to specify a color value for these attributes.
There are certain color names that most browsers will recognize and display properly. These names may be used directly as the value of the attribute. You may also use a hexadecimal code to set the color. Examples of both the color names and the corresponding hexadecimal codes can be seen in the Handy Color Table.
To set the background color of the page to a bright shade of yellow, we can use either the name "Yellow" or the hexadecimal code"ffff00". The tag would then look like:
<BODY BGCOLOR="ffff00">
We can set the color of the text in the same manner. To have the text appear in blue, we can use either the name "Blue" or the hexadecimal code "0000ff"
Using both of the attributes together, the tag would look like:
<BODY BGCOLOR="ffff00" TEXT="Blue">
See an example of what the page would look like
You have control now over the color of the page and of the text. Experiment with the different colors listed at the Handy Color Table. and see what combinations work best. Keep in mind that some color combinations are rather hard to read. Red text on a black background may look really great... until you try to read an entire web page in that combination.
Grab the Code
Review
You have come a long way in a short time. You know know how to create an HTML file, place the content of the page in the <BODY> section, control the alignment of the text with the ALIGN attribute in the <P> tag and have also just learned how to add color to your page with the BGCOLOR and TEXT attributes of the <BODY> tag.
In the next page, we will take a look at how to organize your page using headlines.
Back Next
[Back] [Table of Contents] [Next]
Copyright 2000 John H. Bolgiano, Jr. - All rights reserved
Modified with permission for educational use by Roberta Bush