The main CSS syntax is made of a 'selector' and 'declarations blocks', together forming a 'rule set'.

A rule starts with a selector or selectors followed by a declaration block. The declaration block is omitted by the curly brackets {,} and includes a list of properties.

A declaration consists of a property name, followed by a colon : and a property value; around these items a white space is allowed. A declaration must end with a semicolon ;.

If a few selectors share the same property or properties they may be written in the same statement separated by commas. Similarly, short handed properties like font, may be compressed into one property which values are separated by commas.

Here is the example:

CSS Syntax diagramSome rules are called "at rules". These rules start with the "@" character followed by an identifier (i.e. @import), a statement (i.e. an URI) and end with the semicolon (";").

Comments in CSS start with the /* and end with */. They may be used to comment a particular code or, if surrounding it, to bypass a particular code.

If encountering an improper declaration a browser should ignore it.

Example

CSS syntax:

 

›› go to examples ››