CSS Syntax

CSS Syntax

A CSS rule-set consists of a selector and a declaration block:


Selector indicates the HTML element you want to style. It could be any tag like <h1>, <title> etc.

Declaration Block:

The declaration block can contain one or more declarations separated by a semicolon. For the above example, there are two declarations:

1. color: yellow;

2. font-size: 11 px;

Each declaration contains a property name and value, separated by a colon.


A Property is a type of attribute of HTML element. It could be color, border etc.


Values are assigned to CSS properties. In the above example, value "yellow" is assigned to color property.


Selector{Property1: value1; Property2: value2; ..........;}  


p {
    color: red;
    text-align: center;

In the following example all <p> elements will be center-aligned, with a red text color.