CSS syntax

The CSS syntax consists of a set of rules and comments. Rules have two main parts, a selector and one or more declarations.

Selector defines elements to which rule will be applied. In simple case it can be the html element or a class name. You can grouping and combine selectors.

Declarations are pairs of CSS property and its value in curly brackets. There are more than 100 CSS properties.

example code explanation
body {
  background-image: url("bgImage.jpg");
  background-repeat: no-repeat; /* comment */
  height: 100%;
}
  • Here body is selector
  • Here background-image, background-repeat, height are CSS properties
  • Here url("bgImage.jpg"), no-repeat, 100% are values of corresponding properties
  • Here text between /* and */ is comment text. It can be multiline.