Introduction to HTML: Adding Colors and Fonts
To change the background color, you need to add an attribute and a color value to the opening BODY tag (you never add an attribute to a closing tag!). Here is what the attribute looks like:
- bgcolor="#ffffff"
- <BODY bgcolor="#ffffff">
This is a good time to put in a word about color choices. Subtle is good. You don't want to overwhelm people with your color choices, so bright yellow is probably not a good background color. Always preview your choices in a web browser!
There are more attributes we can put in the BODY tag that will affect the color of text and links on a web page. These attributes are:
- text="#000000"
- link="#0033cc"
- vlink="#ff0000"
If I add these attributes to the BODY tag, it will look like this:
<BODY bgcolor="#ffffff" text="#000000" link="#0033cc" vlink="#ff0000">The background for the page will be white (the bgcolor attribute, "#ffffff" is the hex code for white), the text (the text value, "#000000", is the hex code for black) will be black, links (the link attribute) will be blue, and visited links (the vlink attribute) will be red.
Let's go ahead and add attributes to the BODY tag of our index.html file.
- Open the index.html file in Notepad.
- Replace the opening <BODY> tag with this tag:
<BODY bgcolor="#ffffff" text="#000000" link="#0033cc" vlink="#ff0000"> - Save the file in Notepad then preview it with a web browser.
Introduction to Fonts
All text on a web page is in a font. A font is basically a text style. You know font faces by name: Arial, Courier, Times. Fonts also have sizes and colors. Your browser uses some default font settings: the default face is usually Times and the default size is 3, and the default color is black.But the FONT tag allows you to override those defaults, and display text in special ways.
Here's an example from Webmonkey (an excellent HTML tutorial website from Wired magazine). Take the word:
- TECHNICOLOR
-
<FONT color="#ff0000" size="5">TECHNICOLOR</FONT>
- TECHNICOLOR
- <FONT size="6"> is large
- <FONT size="1"> is tiny
Here is an example of the FONT attributes color, size, and face in action:
- <FONT color="#ff0000" size="3" face="Courier">TECHNICOLOR</FONT>
- TECHNICOLOR
-
<FONT color="#ff0000">T</FONT> <FONT color="#ff7f00">E</FONT> <FONT color="#ffff00">C</FONT> <FONT color="#00ff00">H</FONT> <FONT color="#0000ff">N</FONT> <FONT color="#6b238e">I</FONT> <FONT color="#9932cd">C</FONT> <FONT color="#ff0000">O</FONT> <FONT color="#ff7f00">L</FONT> <FONT color="#ffff00">O</FONT> <FONT color="#00ff00">R</FONT>
- T E C H N I C O L O R
If you use the FONT tag to assign colors, those colors will override any colors you assigned in the BODY tag.
Now let's add some font colors to the index.html page.
- Open the index.html file in Notepad (if it isn't already open!).
- Let's add some contact information to the page. Since my page is for a library, I'm going to add the street address and phone number and I want it to be dark green (hex code is #006633):
- <DL>
- <DD><FONT color="#006633">123 Main Street</FONT>
- <DD><FONT color="#006633">Los Angeles, CA</FONT>
- <DD><FONT color="#006633">ph: 213-555-1122</FONT>
- </DL>
- 123 Main Street
- Los Angeles, CA
- ph: 213-555-1122
After you have added these tags, be sure to save your file then preview it in a web browser. It looks like a real web page! Click here to see my index.html file in its entirety. Notice that my background is now white, and the address text is green. If you click on a link and go back to my index.html page, you will see that the visited links are red. Remember, to see the code of my (or any) web page, open the View menu in your browser and select Source.
Next: Adding Images