liveBook · Manning

Shorthand property

As explained in CSS in Depth, Second Edition

A CSS property syntax that sets multiple related properties, including omitted subvalues that receive their initial values.

A shorthand property sets several related CSS properties in one declaration. It keeps styles concise, but omitted subvalues still receive their initial values and can override inherited or separately declared styles. section 1.4 section 1.4.1

Use shorthand deliberately, checking both its value order and its hidden effects:

  • Treat font as especially broad: font: 32px Helvetica, Arial, sans-serif also sets font-style, font-variant, font-weight, font-stretch, and line-height to their initial values. section 1.4.1
  • Read margin, padding, and related four-side shorthands clockwise: top, right, bottom, left. With fewer values, omitted sides copy from their opposite or adjacent side according to the shorthand rules. section 1.4.2
  • Expect flexible ordering only when the browser can identify each value unambiguously; border: 1px solid black and border: black 1px solid are equivalent, unlike many ambiguous shorthands. section 1.4.2

A title that loses its inherited weight

Given h1 { font-weight: bold; } and .title { font: 32px Helvetica, Arial, sans-serif; }, an h1.title renders with normal weight. Expanding the shorthand reveals why: font-weight: normal is explicitly set by the shorthand, overriding the expected inherited or competing style. Use individual declarations when preserving a particular subvalue matters. section 1.4.1

font: italic bold 18px/1.2 "Helvetica", "Arial", sans-serif;

Inspect the compact font declaration to identify its style, weight, size, line-height, and family components. section 1.4

How CSS in Depth, Second Edition covers it

How deep it goes
Explains definitions, hidden initial values, value order, truncation, and rendered consequences, but does not catalog every shorthand.
Examples
Uses font declarations, four-sided navigation-link padding, truncated padding and margin forms, and box-shadow coordinates.
What it assumes
Assumes basic CSS declarations and selectors while reinforcing cascade, specificity, inheritance, and property-value terminology.
What you can do after
Apply shorthand safely by expanding omitted values mentally, checking ordering, and choosing longhand declarations when preservation matters.
How it connects
Connects shorthand properties to the cascade, specificity, inheritance, font, border, margin, padding, and box-shadow.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.