Turning Learners Into Developers
Codekilla
CODEKILLA
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:

css
selector {
  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 namecolour (UK spelling) doesn't exist; use color.
  • Unit-less values where required — font-size: 16 is invalid; use 16px.
Interview Questions

Practice Exercises
  1. Three rules — Style h1, .card, #hero differently. Hint: snippet above.
  2. Multiple props — One selector, 5 properties. Hint: stacking declarations.
  3. Spot the bugh1 { 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
Explore examples
// glossary lookup
Every term you just saw, explained
Quick definitions for variables, pointers, loops, functions and every concept in one searchable page.
Open Terminology
// feedback.matters()
Did this lesson help you?