CSS · Unit 1: Styling basics · Lesson 1 of 5
How CSS works
CSS styles HTML.
Opens this lesson in Code Academy.
The idea
CSS styles HTML. A rule has a selector, which picks elements, followed by declarations in curly braces: p { color: navy; }
Each declaration is a property, a colon, a value and a semicolon. The property is what to change; the value is how.
In these lessons the HTML is given to you and your CSS goes in the editor. The preview shows the result as you type.
Worked example
CSS
h1 {
color: darkslategray;
}
p {
color: dimgray;
font-size: 18px;
}
The HTML it styles
<h1>Lighthouse Tours</h1>
<p>Trips leave every hour.</p>
Key terms
- Rule
- A selector followed by declarations in curly braces: p { color: navy; }
- Selector
- The part of a rule that picks elements: p, .note, #top, nav a or *.
- Declaration
- A property, a colon, a value and a semicolon: color: navy;
Practise it in Code Academy
It has 4 exercises (multiple choice, fill in the blank, fix the broken code and write code from a prompt) and takes about 6 minutes. Every answer is checked as you go, and feedback names the exact mistake. Hints and the solution are there if you get stuck.
Every lesson is free: no ads, no lives and no paywall.