Loading

CSS Syntax

  • CSS syntax consists of a set of rules that define how HTML elements should be styled.

Syntax:

h1{color:yellow; font-size: 10px;}

In the above syntax:

  • h1:selector
  • color: property
  • yellow: value

  • Selector: Selector indicates the HTML elements that we want to style. It could be any tags like <p>,  etc.
  • Declaration Block: The declaration block can contain declarations, and a semicolon separates them. 

      There are two declarations:

  1. color: red;
  2. font-size: 5 px;
  • Property: It is an attribute of an HTML element. It could be color, border etc.
  • Value: Values are assigned to CSS properties. In the Declaration block example, a value "red" is assigned to a property color.
Selector{Property1: value1; Property2; value2; ..........;}  

Example:

selector {
    property1: value1;
    property2: value2;
}

selector declaration always ends with a semicolon, and curly braces surround declaration blocks.