liveBook · Manning

Chapter 11: Color and contrast

What you will learn in chapter 11 of CSS in Depth, Second Edition

The introduction frames implementing a designer’s mockup as translating a specific design into reusable CSS while respecting its design intent.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction frames implementing a designer’s mockup as translating a specific design into reusable CSS while respecting its design intent.

Key terms: mockup, HTML and CSS, reuse, designer’s concerns, spacing, colors, typography, design principles

11.1 Communicating with contrast

This section explains how designers use consistent visual patterns and deliberate contrast to guide attention toward a page’s most important content.

Key terms: contrast, hierarchy of information importance, patterns, modular CSS, reuse of styles, color, spacing, size, whitespace

11.1.1 Establishing patterns

This section shows how repeated design details establish a visual pattern that should remain consistent when a mockup is implemented and the site evolves.

Key terms: visual pattern, mockup, designer’s vision

11.1.2 Implementing the design

This subsection sets up the page and stylesheet for the chapter’s design and explains how its BEM-style class names identify module parts and variants.

Key terms: page, stylesheet, markup, BEM-style notation, module, subelements, variants

11.2 Defining color

This section shows how to turn a designer’s color palette into reusable CSS colors while roughly styling the page and using contrast to guide attention.

Key terms: color palette, primary color, Brand Green, custom properties, hex color values, double-container pattern, nav-container, top-nav, hero, tile-row

11.2.1 Gamuts and color spaces

This section explains why CSS needs newer color notations, distinguishes color gamuts from color spaces, and shows how to detect a device’s supported gamut.

Key terms: gamut, hex notation, sRGB, Display p3, Rec2020, color space, RGB, HSL, hue, lightness

11.2.2 CSS color notations

This section explains how CSS color notations express colors, how newer color spaces differ from sRGB, and why OKLCH is useful for working with color.

Key terms: hex color, rgb(), sRGB gamut, hsl(), hwb(), hue, saturation, lightness, whiteness, alpha channel

11.3 Using OKLCH to work with color

This section shows how to use browser DevTools to convert CSS colors to OKLCH or another notation and interpret the color picker’s gamut boundary.

Key terms: DevTools, Elements panel, Styles panel, custom properties, color picker, OKLCH, wide gamut color space, sRGB gamut, Display p3

11.3.1 Switching the stylesheet to OKLCH

The section converts a site’s hex colors to OKLCH to reveal relationships in its palette and make related colors easier to create.

Key terms: hex, OKLCH, hue, lightness, chroma, DevTools, gray, browser support, fallback values

11.3.2 Naming color variables

This section explains how to name color custom properties so a palette can grow and colors can change without unexpectedly affecting other uses.

Key terms: raw color variables, lightness, custom properties, secondary variables, foreground and background colors, light mode and dark mode

11.3.3 Selecting new colors for the palette

The section motivates adding a color to an existing palette when a needed color was not planned, using active links as an example.

Key terms: palette, active link color, user-agent stylesheet

11.3.4 Deriving colors from others on the page

This section shows how to derive colors from an existing palette using complementary hues, an OKLCH color picker, color-mix(), and relative color syntax.

Key terms: complement, hue, chroma, lightness, DevTools, oklch.com, gamut, sRGB, Display p3, fallback color

11.4 Considering contrast for font colors

The section explains how to choose readable font colors by balancing visual comfort, WCAG contrast guidance, measured ratios, and the effect of font weight.

Key terms: contrast, dark gray, light gray, WCAG, contrast ratio, level AA, level AAA, large text, contrast checker, font weight

11.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 10: Container queries Chapter 12: Typography and spacing →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.