Web Technologies 2026 · BiUH · Lesson 3
Cascading Style Sheets
Syntax · how to apply it · the cascade · specificity · inheritance
What this lesson covers
| Syntax | what a rule is made of |
| Three ways in | inline, internal, external — and which to use |
| The cascade | what happens when two rules disagree |
| Specificity | why your rule is being ignored |
| Inheritance | what children get for free |
The last three are where CSS stops being obvious. They are why this lesson exists.
HTML says what things are.
CSS says what they look like. Separating them means you can restyle an entire site without touching a single line of content.
And a page with no CSS still works — it just looks plain.
The shape of every rule you will ever write
selector {
property: value;
}
/* a real one */
p {
color: #333;
font-size: 16px;
}
Selector — which elements. Property — what aspect. Value — what setting.
The semicolon ends each declaration. Forgetting it silently breaks the next line — a classic first-week bug.
Three ways to apply it
<p style="color:red">
One element. Impossible to reuse, hard to override.
<style>
p { color: red; }
</style>
One page. Fine for a quick test.
<link rel="stylesheet"
href="style.css">
Every page. One file to change. Cached by the browser.
Use external. Almost always.
Lesson 3 · the hard part starts here
Two rules, one element. Which wins?
This is the C in CSS — the name is telling you that conflicts are expected, and that there are rules for settling them.
Three questions, in this order
!important?p { color: blue; }
p { color: red; } /* red wins — same specificity, written later */
Most "why isn't my CSS working" questions are answered by step 2, not step 3.
Specificity · the weights
p, h1, div0,0,0,1.intro0,0,1,0#header0,1,0,0style="…"1,0,0,0!importantbeats everythingRead it as a four-digit number. A single id beats any number of classes.
Count them yourself
p → 0,0,0,1
.intro → 0,0,1,0
p.intro → 0,0,1,1
#header → 0,1,0,0
#header .nav → 0,1,1,0
div#header .nav p → 0,1,1,2
When a style refuses to apply, open DevTools: the overridden rule is shown struck through, and the winner is above it.
That strike-through is the fastest debugging tool in CSS. Look for it first.
A warning worth taking seriously
!important is not a fix.
It wins — and that is the problem. The next conflict needs another
!important, and soon nothing can be overridden by anything.
If you need it, the real answer is almost always a more specific selector, or a better-organised stylesheet.
Inheritance · what you get for free
color, font-family, font-size,
line-height, text-align
Text properties. Set them once on body.
margin, padding, border,
background, width
Box properties. Every element decides its own.
The split is logical: text flows down, boxes do not.
Lesson 3 · done
!important makes tomorrow harderwebtech.landrock.io/demos/box-model.html
Next: the box model — try the live demo.