4.1 CSS syntax

CSS code consists of one or more rules.

Each CSS rule consists of a selector and, within brackets, one or more properties.

The selector specifies which HTML elements the rule applies to and the properties control the way that those HTML elements are displayed. An example of a CSS rule is shown below:

a {
    color: white;
}

The code a is the selector and the property is color, with the value white.

selector: a {
property name:      color: white;
property value:     color:  white;
  }

Just as for HTML, it is important to check CSS code for correct syntax. Most browsers will silently ignore errors in CSS code. For example, if a CSS property is not spelled correctly, it will just appear not to be working in the browser. The W3C provides an online validation service (see Section 4.5).

Paul Murrell

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License.