back to course
Lesson 02 / 962%· free preview
CSS Basics2/7
CSS Syntax
Selectors, properties, values — the anatomy of every CSS rule.
Definition
A CSS rule has 3 parts:
cssselector { property: value; }
- Selector — which HTML elements to style.
- Property — what aspect to change (
color,font-size). - Value — what to change it to (
red,16px).
Anatomy of a CSS Rule
css/* Match all <h1> elements */ h1 { color: orange; font-size: 48px; font-family: "Inter", sans-serif; } /* Match elements with class="card" */ .card { padding: 1rem; background: white; border-radius: 8px; } /* Match the element with id="hero" */ #hero { height: 400px; background: linear-gradient(orange, red); }
Anatomy
h1 { color: orange; }
└┬┘ └──────┬──────┘
selector declaration block
│
└─ color: orange;
└─┬─┘ └─┬──┘
property value
└ separator (semicolon)
Common Mistakes
- Missing
;between declarations — last one is forgiving but middle ones break. - Forgetting
{ }— rules silently ignored. - Wrong property name —
colour(UK spelling) doesn't exist; usecolor. - Unit-less values where required —
font-size: 16is invalid; use16px.
Interview Questions
Practice Exercises
- Three rules — Style
h1,.card,#herodifferently. Hint: snippet above. - Multiple props — One selector, 5 properties. Hint: stacking declarations.
- Spot the bug —
h1 { color red }(no colon) — fix it. Hint: missing:.
💡 Think Like a Programmer: Selector { property: value; } — this is the only pattern in all of CSS. Master it and the rest is just vocabulary.
AI-powered recap
Quick recap quiz?
We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.
Ready to move on?
// example library
Want more hands-on snippets in CSS3?
Browse 1 runnable example · across 1 chapter · short, copy-paste-friendly · grouped by topic
// glossary lookup
Every term you just saw, explained
Quick definitions for variables, pointers, loops, functions and every concept in one searchable page.
// feedback.matters()
Did this lesson help you?
