Web Technologies 2026 · BiUH · Lesson 3

CSS

Cascading Style Sheets

Syntax · how to apply it · the cascade · specificity · inheritance

webtech.landrock.io

What this lesson covers

Five ideas.

Syntaxwhat a rule is made of
Three ways ininline, internal, external — and which to use
The cascadewhat happens when two rules disagree
Specificitywhy your rule is being ignored
Inheritancewhat 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

Inline

<p style="color:red">

One element. Impossible to reuse, hard to override.

Internal

<style>
  p { color: red; }
</style>

One page. Fine for a quick test.

External ✓

<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

The cascade

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

How a conflict is settled.

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

element — p, h1, div0,0,0,1
class — .intro0,0,1,0
id — #header0,1,0,0
inline — style="…"1,0,0,0
!importantbeats everything

Read 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

Inherited

color, font-family, font-size, line-height, text-align

Text properties. Set them once on body.

Not inherited

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

What you should be able to say now.

webtech.landrock.io/demos/box-model.html

Next: the box model — try the live demo.

← → navigate · F fullscreen · P print · Copy never turns the page