<htmlstart/>

CSS Syntax

Learn the basic rules for writing CSS.

The CSS Rule

A CSS rule has two parts: a selector that targets HTML elements, and a declaration block with property–value pairs.

selector {
  property: value;
  property: value;
}
h1 {
  color: #D62828;
  font-size: 32px;
  margin-bottom: 16px;
}

Key Points

  • Each declaration ends with a semicolon ;
  • The declaration block is wrapped in curly braces { }
  • Property and value are separated by a colon :
  • CSS is case-insensitive but convention is lowercase

Comments

/* This is a CSS comment */
p {
  color: blue; /* inline comment */
}
Use comments to label sections of your stylesheet — e.g. /* === Header === */
🧩

Test Yourself

4 questions
Q1.What separates a CSS property from its value?
Q2.What character ends each CSS declaration?
Q3.CSS declarations are wrapped in ___
Q4.Which syntax is used for CSS comments?