CSS rule syntax

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

This CSS rule syntax worksheet is part of the HTML and CSS Journey journey. Print it as a booklet?

CSS rule syntax

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which part of a CSS rule chooses the elements to style?
A The declaration block
B The selector
2. What separates a property from its value?
A A colon, as in color: red
B A semicolon, as in color; red
3. What ends each declaration?
A A semicolon
B A comma
4. Which symbols wrap the declarations in a rule?
A Curly braces { }
B Round brackets ( )
5. Which is a complete, correct declaration?
A color = blue;
B color: blue;

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1p Ablue
2color BRound brackets used where curly braces are needed
3The setting given to the property CThe property: names the thing about the element to change
4Wrap the declarations of one rule DThe selector: chooses which elements the rule applies to
5color blue; EThe colon between property and value is missing
6p ( color: red; ) F{ }

Definitions

selector { property: value; }

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
__ { color: red; }
2.
p { ______ blue; }
3.
p { color: _____ margin: 0; }
4.
______ margin: 0; }
5.
a { color: green; ________________ }

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A p {
B color red;
C }
Question 2
A h1 {
B color: blue
C font-size: 2rem;
D }
Question 3
A p
B color: red;
C }
Question 4
A body (
B margin: 0;
C }
Question 5
A p {
B color; red;
C }

Answer Key

CSS rule syntax
Section A: Quick Questions
Q1
B — The selector
Q2
A — A colon, as in color: red
Q3
A — A semicolon
Q4
A — Curly braces { }
Q5
B — color: blue;
Section B: Match the Pairs
Q1
p → The selector: chooses which elements the rule applies to
Q2
color → The property: names the thing about the element to change
Q3
The setting given to the property → blue
Q4
Wrap the declarations of one rule → { }
Q5
color blue; → The colon between property and value is missing
Q6
p ( color: red; ) → Round brackets used where curly braces are needed
Section C: Definitions
Q1
selector { property: value; } — A CSS rule: the selector picks the elements, and each property: value; pair inside the curly braces styles them.
Section D: Fill in the Blanks
Q1
h1 { color: red; }
Q2
p { color: blue; }
Q3
p { color: blue; margin: 0; }
Q4
body { margin: 0; }
Q5
a { color: green; font-size: 18px; }
Section E: Spot the Error
Q1
B — The colon is missing between the property and the value. It should be color: red; because every declaration needs a colon.
Q2
B — The color declaration has no semicolon. It should be color: blue; so the browser knows where it ends.
Q3
A — The opening curly brace is missing after the selector. It should be p { so the declaration block has a start.
Q4
A — The block opens with a round bracket. It should be body { because declaration blocks use curly braces.
Q5
B — A semicolon was typed where the colon belongs. It should be color: red; with a colon after the property.