Selector, property, value
A CSS rule has a fixed shape: selector { property: value; }. The selector says which part of the page, the property says what to change, and the value says how. Between the curly brackets we write the property, a colon, the value and a semicolon. Look at the three rules in the picture. The first says that every h1 heading (selector h1) gets dark blue text (property color, value darkblue) and is centred. The second says that every paragraph gets letters of size 18px (px means pixels, tiny dots on the screen). The third gives the whole page (body) a very pale blue-green background. Colour names have no spaces: lightcyan is correct and light blue is not. Always finish each line with a semicolon.
1h1 { 2 color: darkblue; 3 text-align: center; 4} 5p { 6 font-size: 18px; 7} 8body { 9 background-color: lightcyan; 10}
| Selector | Property | Value |
|---|---|---|
| h1 | color | darkblue |
| h1 | text-align | center |
1p { 2 font-size: 18px; 3 color: black; 4}
Write your own three CSS rules on paper for an invented page: one for h1, one for p and one for body. For each rule, underline the selector, circle the property and put a box around the value. Use only colour names without spaces.