CSSLesson 1 of 10Jump to practice
What is CSS?
CSS controls how HTML looks. Learn what a CSS rule is made of and where to put it.
HTML says what things are. CSS (Cascading Style Sheets) says how they should look: colors, sizes, spacing and layout.
A CSS rule
A CSS rule has two parts: a selector that picks elements, and a declaration block that says what to change.
h1 {
color: teal;
font-size: 40px;
}
h1is the selector. This rule applies to every<h1>.color: teal;is a declaration: a property, a colon, a value and a semicolon.
Change some values below and press Run.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: teal;
font-size: 40px;
}
p {
color: dimgray;
font-family: Georgia, serif;
}
</style>
</head>
<body>
<h1>Styled heading</h1>
<p>This paragraph is styled by CSS.</p>
</body>
</html>Three places to write CSS
| Where | Example | When to use it |
|---|---|---|
| A separate file | <link rel="stylesheet" href="style.css"> |
Real websites. One file styles every page |
A <style> element |
<style> p { color: red; } </style> |
Learning, and single pages like the examples here |
A style attribute |
<p style="color: red"> |
Rarely. Quick one-off changes |
Practice
Check what you just learned. Fill in the missing code, then answer the quiz.
Exercise 1Solved
Make every paragraph's text blue.
p { : blue; }CSS uses the American spelling.
Exercise 2Solved
Complete the rule so every
<h1>has a font size of 32px.h1 { font-size: ; }Write the number and the unit with no space between them.
Exercise 3Solved
Link the stylesheet file
style.cssto the page.<link rel="" href="style.css">The value describes what kind of file is being linked.
Finish the practice to complete this lesson.
Sign in to keep your progress on any device.