CSS: Applying CSS Rules

CSS is applied by following three simple rules:

  1. Identifying the HTML element to style. This element is called the “selector”.
  2. Specifying the property of the HTML element which is to be changed (e.g. colour, size, font, etc)
  3. Assigning a value (numerical or written) to the chosen property.

For example, below is CSS coding at its simplest with a selector (“p“, which in HTML stands for paragraphs), two properties (“text-align” and “color“) and two corresponding values (“center” and “red“).

p { text-align: center; color: red; }

This piece of CSS code will style all the <p> elements in a linked HTML document so that they are centered and in colour red.