Skip to Content
HTML, XHTML, and CSS Bible, Fifth Edition
book

HTML, XHTML, and CSS Bible, Fifth Edition

by Steven M. Schafer
January 2010
Intermediate to advanced
791 pages
14h 17m
English
Wiley
Content preview from HTML, XHTML, and CSS Bible, Fifth Edition

Chapter 33. Colors and Backgrounds

IN THIS CHAPTER

  • Element Colors

  • Background Images

The previous chapter covered the box formatting model of CSS. You learned how you can manipulate an element's concentric boxes to better format your HTML documents. This chapter continues the discussion, covering element foreground and background colors, and the use of images for element backgrounds.

Element Colors

Most elements in an HTML document have two color properties, a foreground property and a background property. Both of these properties can be controlled using CSS styles. The following sections discuss both types of color properties.

Foreground colors

An element's foreground color is typically used on the visible portion of that element. In most cases, the visible foreground portion of an element is text, but there are instances where the foreground contains other, nontextual components. You can control the foreground color of an element using the CSS color property, which has the following format:

color:  <color_value>;

As with other properties that use color values, the value of the color property can be expressed using one of three methods:

  • Predefined color keywords (such as blue, red, black, or green)

  • Hexadecimal color values in #rrggbb form (#000000 for black, #FF0000 for red, #FF00FF for dark purple, and so on)

  • An RGB value using the rgb() function (rgb(100%,0%,0%) or rgb(255,0,0) for red)

For example, the following style defines a class of the paragraph element, which will be rendered with a ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

HTML, XHTML, and CSS Bible, Fourth Edition

HTML, XHTML, and CSS Bible, Fourth Edition

Steven M. Schafer

Publisher Resources

ISBN: 9780470523964Purchase book