CSS Basics
CSS: where a button becomes beautiful… or invisible.
▶ the lesson · narrated sketch video · tap for sound
the intro
CSS is how pages get their look: colors, spacing, fonts, layout. You write selectors that find elements and declare what they should look like. The trick is learning the box model and the cascade — once those click, CSS stops being random.
the sample
one selector, three declarations
button {
background: #4a7cf6;
color: white;
border-radius: 999px;
}fun fact ✦
CSS was first proposed by Håkon Wium Lie in 1994 — and the cascade debates never ended.
the docs
the deep dive
the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid
CSS has a reputation for randomness it does not deserve. It is a court system: when two rules disagree, fixed tiebreakers decide — origin, then specificity, then source order. Learn the tiebreakers and the box model, and the apparent chaos resolves into procedure.
the cascade is a tiebreaker, not chaos
key terms
selector
The find-part of a rule: which elements does this apply to? Tags, classes, ids, and pseudo-classes all match differently.
.card > h2:hoverdeclaration
One property-value pair inside a rule. A rule is just a list of these.
color: #4a7cf6;specificity
The cascade's tiebreaker score: inline beats id, id beats class, class beats tag.
id: 100, class: 10, tag: 1box model
Every element is content wrapped in padding, border, and margin. Sizing bugs are almost always this model misunderstood.
box-sizing: border-boxhow it works
- 1Collect matching rules
The browser finds every rule whose selector matches the element, from your stylesheets and the browser defaults.
- 2Sort by specificity
Higher specificity wins. An id beats ten classes, which beats a hundred tags.
- 3Break ties with order
Equal specificity? The rule written later in the file takes it. This is why import order matters.
- 4Resolve inheritance
Properties like color and font flow down from parents unless something overrides them. The result is the computed style that gets painted.
the code, explained
the reset that ends width math forever
side by side
border-box
- width includes padding + border
- the number you set is the size
- default in every framework
- mental math: none
content-box
- width is content only
- padding adds on top of it
- the raw CSS default
- a debugging classic
!important is a debt with compound interest. It beats specificity, so the only way to override it later is another !important, and six months in nobody remembers why any of them exist. Reserve it for utility classes and third-party overrides — nowhere else.
quick answers
Why is my rule being ignored?
Three usual suspects: a more specific rule won, a tie went to a later rule, or the selector has a typo. DevTools shows the winner and crosses out the losers.
rem or px?
rem for anything that should scale with the user font setting — it is an accessibility feature. px is fine for hairlines and shadows.
Do I still need raw CSS if I use Tailwind?
Yes. Every utility class is a CSS declaration in costume; the cascade and the box model decide whether your layout works either way.
quick hits about CSS Basics
short answers · interviews, tips, trivia & hidden gems
What is the CSS box model?watch ↗
Which CSS rule wins?watch ↗
Why did your CSS get ignored?watch ↗
Variables in CSS?watch ↗
A keyword that inherits color?watch ↗
Fluid font sizes without media queries?watch ↗
Inherit, initial, unset — know the difference?watch ↗