CSS Syntax

Every CSS rule follows a simple syntax: selector + declaration block. The declaration block contains one or more property:value; pairs.

Basic Syntax


selector {
  property: value;
}

Example:


p {
  color: blue;
  font-size: 16px;
}

This targets all <p> elements, sets the text color to blue and font size to 16px.

Multiple Selectors


h1, h2, p {
  color: darkgreen;
}

Applies the same rule to multiple elements at once.

CSS Comments


/* This is a CSS comment */
p {
  color: red; /* change text color */
}

Comments start with /* and end with */. They are ignored by browsers.

Quick Notes:

  • Selector → chooses the HTML element(s) to style.
  • Property → the style attribute you want to change.
  • Value → the setting applied to the property.
  • Each declaration ends with a semicolon ;.
  • You can group multiple declarations inside one block { }.