Chapter 9. Colors and Backgrounds

Most of us take color for granted. For web professionals, it’s a big heap of details. Experienced developers need to know how to relate color data to their literal counterparts, and the body of related knowledge gets trickier and more subjective from there. Web color is about the numbers and the art, and it never hurts to understand the two together.

Backgrounds offer challenges of their own. Assigning a flat background color to an element is a straightforward task, but once images enter the picture the implementation questions start to multiply.

Note

This book doesn’t cover web color and graphics in depth, but there are plenty of good resources out there. A number of sites are linked from this book’s companion site. I also recommend the following books:

  • Web Style Guide, Third Edition, by Sarah Horton and Patrick Lynch (Yale University Press)

  • Painting the Web by Shelley Powers (O’Reilly)

Color Theory and Web Color Practice

The CSS 2.1 properties that can take color values are the various background and border properties. There’s also the color property, which sets the text and underline colors of the elements to which it is applied.

Usability, Accessibility, and Color

When assigning colors and background colors to two elements, adhere to the following:

  • Where background or background-color is used in a stylesheet rule, color should follow—and a background color reference should always precede a color value. This prevents odd user agent or user ...

Get HTML & CSS: The Good Parts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.