O'Reilly logo

HTML & CSS: The Good Parts by Ben Henick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 stylesheet defaults ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required