liveBook · Manning

Chapter 1: Cascade, specificity, and inheritance

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

The chapter introduction explains why CSS requires a grasp of underlying principles and reviews the syntax terms used throughout the book.

After this chapter you will be able to

Section by section

Introduction

The chapter introduction explains why CSS requires a grasp of underlying principles and reviews the syntax terms used throughout the book.

Key terms: principles, constraints, edge cases, declaration, property, value, attribute, declaration block, selector

1.1 The cascade

This section introduces the cascade as CSS’s predictable way to resolve conflicting declarations and identifies the criteria it considers.

Key terms: cascade, conflicting declarations, ID selector, stylesheet origin, inline styles, layer, selector specificity, scope proximity, source order

1.1.1 Stylesheet origin

This section explains how stylesheet origins and !important declarations determine which conflicting CSS declarations win, while the cascade resolves each property separately.

Key terms: author styles, user styles, user-agent styles, origin, !important, important declarations, normal declarations, cascade, property, user-agent stylesheet

1.1.2 Inline styles

Explains how inline styles affect the cascade and when a stylesheet declaration can override them.

Key terms: inline styles, style attribute, selector, !important, higher-priority origin, inline declarations

1.1.3 Selector specificity

This section explains how selector specificity resolves CSS conflicts and how to avoid escalating specificity when a rule does not take effect.

Key terms: specificity, ID selector, class selector, tag selector, pseudo-class selectors, attribute selectors, universal selector, combinators, #main-nav a, .featured

1.1.4 Source order

This section explains how source order resolves tied CSS declarations and how that affects selector choices, link states, and maintainable styles.

Key terms: source order, order of appearance, specificity, compound selector, a.featured, featured class, :link, :visited, :hover, :active

1.2 Inheritance

Explains when CSS properties inherit from ancestors, which kinds of properties normally inherit, and how DevTools reveals inherited and overridden styles.

Key terms: inheritance, cascaded value, ancestor element, descendant elements, inherited properties, font-family, list-style, border-collapse, border-spacing, DevTools

1.3 Special values

Introduces four special CSS values that can be applied to any property to manipulate the cascade.

Key terms: inherit, initial, unset, revert, cascade

1.3.1 The inherit keyword

This subsection shows how `inherit` overrides a cascaded value so an element takes a property value from its parent.

Key terms: inherit, cascaded value, parent, border, padding

1.3.2 The initial keyword

Explains how `initial` resets a CSS property to its property-wide default value, including why that may differ from an element’s usual display.

Key terms: initial, initial value, auto, display: initial, display: inline, revert

1.3.3 The unset keyword

Explains how `unset` clears a CSS value according to whether its property is inherited, and why it cannot restore every element default.

Key terms: unset, inherit, initial, inherited property, noninherited property, initial value, text-decoration: underline, text-decoration

1.3.4 The revert keyword

The section explains how `revert` undoes author styles while retaining browser defaults, and notes that it remains subject to the cascade.

Key terms: revert, initial, unset, author styles, user-agent stylesheets, text-decoration, cascaded values, higher specificity

1.4 Shorthand properties

Defines CSS shorthand properties, illustrates the longhand properties they group, and notes their benefit for concise code.

Key terms: shorthand properties, font, background, border

1.4.1 Beware shorthands silently overriding other styles

This subsection explains why omitted values in CSS shorthands can silently override other styles.

Key terms: shorthand properties, initial value, font, font-weight

1.4.2 Remember the order of shorthand values

This section explains how value order works in CSS properties, especially four-sided spacing and horizontal–vertical measurements.

Key terms: shorthand properties, border, margin, padding, top, right, bottom, left, TRouBLe, truncated notations, vertical padding, horizontal, background-position

1.5 Progressive enhancement

Introduces progressive enhancement as a way to use new CSS features while preserving an acceptable experience in browsers that do not support them.

Key terms: progressive enhancement, forward and backward compatible, browser support, evergreen

1.5.1 Using the cascade for progressive enhancement

Shows how the cascade provides a usable fallback when a browser does not understand a newer CSS declaration.

Key terms: progressive enhancement, cascade, declaration, cascaded value, 8-digit hex color code

1.5.2 Progressively enhancing selectors

Explains how to use new CSS selectors without letting unsupported selectors suppress styles that older browsers could apply.

Key terms: ruleset, selector, unsupported or invalid, pseudo-class

1.5.3 Feature queries using @supports()

Explains how @supports lets CSS provide fallback styles and enhanced styles according to browser support, and why that supports progressive enhancement.

Key terms: feature query, @supports, declaration, fallback, progressive enhancement, grid, not, or, and, selector()

1.6 Summary

Where this is used later

Concepts explained in this chapter

Chapter 2: Working with relative units →

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.