liveBook · Manning

Declaration

As explained in Web Design Playground, Second Edition

A CSS declaration is a property-value pair that specifies a presentation setting.

A CSS declaration is a property-value pair: an instruction telling the browser how to display part of a page. For example, `font-size: 36px;` asks the browser to make text 36 pixels tall. section 2.3

Build a declaration from these pieces:

  • Write the property name, such as `color`, `font-size`, `margin`, or `display`. section 2.3
  • Add a colon, a value, and any necessary unit: `font-size: 36px`. section 2.3
  • Finish with a semicolon. The final declaration in a group may omit it, but keeping it makes styles easier to extend. section 2.3
  • Place declarations inside curly braces to form a declaration block; attach that block to a selector to create a style rule. section 2.16 section 2.3

A declaration in action

This rule contains one declaration: `h1 { font-size: 36px; }`. The `h1` selector chooses the headings, while `font-size: 36px;` supplies the browser’s presentation instruction. A declaration can also activate a larger feature: `.container { display: grid; }` turns the element into a grid container. section 2.3 section 13.2

h1 {                         #1
    font-size: 36px;         #2
}                            #3

Inspect the compact `h1` rule to see the selector, declaration, and closing brace together. section 2.3

How Web Design Playground, Second Edition covers it

How deep it goes
Defines syntax, grouping, spacing, units, and placement, while deferring the broader methods for adding styles.
Examples
Uses `font-size: 36px;` for headings and `display: grid;` for a container.
What it assumes
Assumes basic web page elements and introduces CSS properties, values, selectors, and style-rule structure.
What you can do after
Apply it via CSS syntax to change selected elements’ presentation or activate layout behavior.
How it connects
Connects properties and values with selectors, declaration blocks, style rules, style sheets, and grid containers.

Also explained in

Compare how 4 books explain declaration →

Related concepts

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