CSS Syntax

❮ Previous Home Next ❯

CSS rules are defined as a property name followed by a colon and then a property value.

Individual rules are terminated by semicolons, with the final rule having an optional semicolon(but not recommended).

CSS Syntax

The selector specifies which element(s) in the HTML page the CSS rule applies to.

The declarations within the block determines how the elements are formatted on a webpage.

The declaration consists of a property and a value separated by a colon : and ending with a semicolon ;, and the declaration groups are surrounded by curly braces {}.

Each property has a value, for example color property can have value #FF0000 etc.


p {
  background-color: yellow;
  color: red;

In above example all <p> elements background color will be yellow and text color will be red


To make the CSS more readable, you can put one declaration on each line.

CSS property names and many values are not case-sensitive. Whereas, CSS selectors are usually case-sensitive, for instance, the class selector .example is not the same as .Example.

❮ Previous Home Next ❯