In HTML, how do I change the color of the text and background of a web page?
To change the color of the text and background of a web page, you need to include extra attributes within the HTML <body> tag. If the site you are creating contains more than one page, you can specify these attributes for all your pages in a single style sheet. For more information, see What is CSS?
Use the bgcolor attribute to change the background color, as follows:<body bgcolor="#rrggbb">
The color value is specified with two hexadecimal digits each for red, green, and blue intensities. A value of 00 is darkest and ff is lightest, with intermediate values specifying shades in between. To specify white, for example, use #ffffff. To specify bright blue, use #0000ff. For purple, use #ff00ff. For more information, see What are the RGB values of some common colors? and What are the 216 web browser-safe colors?
You can use other attributes in a similar way to specify the colors used to display text. Use the text attribute for normal text, the link attribute for unvisited links, the vlink attribute for previously visited links, and the alink attribute for active links. (A link becomes active when you click it.) For example, to make all normal text appear white and all links appear red, you would use:<body text="#ffffff" link="#ff0000" vlink="#ff0000" alink="#ff0000">
You can also change the text color of individual words or sections rather than entire documents by using the <font> tag with the color attribute, for example:<font color="#000000">
You can use any of the hexadecimal numbers representing colors, as described above. To turn off the color change, use a </font> tag.
Choose your colors carefully so that your text will be easily visible. For example, if you're using a dark background color, you should use light colors for text and links to ensure legibility.
Last modified on July 05, 2011.