Connect a stylesheet and understand the cascade
Create a separate stylesheet, target elements, and use DevTools to see which declaration wins.
- Difficulty
- beginner
- Time
- 40 minutes
- Last verified
- 9/21/2026
What you will build
Create a separate stylesheet, target elements, and use DevTools to see which declaration wins.
Understand the idea first
Selectors decide what matches; the cascade resolves conflicts.
Build it step by step
/* css/style.css */
:root {
color-scheme: light;
}
body {
color: #1f2937;
background: #fffaf5;
}
.site-title {
color: #c2410c;
}
header .site-title {
color: #9a3412;
}- Create
css/style.css. - Link it from every HTML page, adjusting relative paths for nested files.
- Add
class="site-title"to the main heading and verify the rule applies. - Use DevTools Styles to explain overridden declarations.
Read the important lines
- Selectors decide what matches; the cascade resolves conflicts.
- Classes are reusable styling hooks; avoid ids for routine styling.
- Confirm the file loaded before debugging specificity.
Common mistakes and what to check
| Symptom | What to check |
|---|---|
| No styles apply | Check the relative link and Network 404s. |
| A declaration has no effect | Check spelling, matching, and overrides. |
Practice without copying
Add .nav-link to navigation, write a class rule and a header .nav-link rule, then predict the winner.
Check the answer after you try
DevTools should show both matches; the compound selector wins until removed.
Completion check
- I produced the required visible result
- I can explain the input, processing, and output
- I tested normal, edge, and failure cases