
In this lesson, you’ll learn the most important core concepts of CSS that control how styles actually work: CSS syntax, selectors, cascade, inheritance, and specificity.
If CSS ever felt random or frustrating, it’s usually because one of these rules was unclear. Once you understand them, CSS becomes predictable, logical, and easy to debug.
Info!
Every CSS framework (Bootstrap, Tailwind, custom design systems) is built on these exact fundamentals.
1. CSS Syntax (How CSS Is Written)
CSS is written using rules. A rule tells the browser what to select and how to style it.
selector {
property: value;
}
Example rule:
Here:
pis the selectorcolorandfont-sizeare propertiesblueand18pxare values
2. CSS Selectors (Targeting Elements)
Selectors decide which HTML elements receive styles. Choosing the right selector is key to clean and maintainable CSS.
| Selector | Example | Use Case |
|---|---|---|
| Element | p |
Style all elements of one type |
| Class | .card |
Reusable styling (best practice) |
| ID | #header |
Unique element only |
Warning!
Avoid styling everything with ID selectors. They make CSS hard to override.
3. CSS Cascade (Which Rule Wins?)
When multiple CSS rules target the same element, the browser uses the cascade to decide the final style.
Cascade priority:
!important(avoid using)- Specificity
- Source order (last rule wins)
Info!
CSS is not executed like JavaScript. Order and priority matter.
4. CSS Inheritance (Automatic Style Flow)
Some CSS properties automatically pass from parent elements to child elements. This is called inheritance.
Inherited properties include:
- color
- font-family
- font-size
Tip!
Inheritance reduces repetitive CSS and keeps styles consistent.
5. CSS Specificity (Rule Strength)
Specificity defines which selector is stronger when multiple rules apply.
Specificity order (low → high):
- Element selector
- Class selector
- ID selector
- Inline styles
Warning!
Using !important breaks specificity logic and creates long-term CSS problems.
What You Learned
- CSS syntax and rule structure
- How selectors target elements
- How the cascade resolves conflicts
- How inheritance works automatically
- How specificity controls rule priority
Next lesson: CSS Colors, Units & Typography