CSS Syntax

A CSS rule has two main parts: a selector, and one or more declarations:

Css Syntax
  • Selector: A selector is an HTML tag at which style will be applied. This could be any tag like <h1> or <table> etc.
  • Property: A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties.
  • Value: Values are assigned to properties. For example color property can have value either red or #F1F1F1 etc.

CSS Example

A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets:
    p {color:red;text-align:center;}
To make the CSS more readable, you can put one declaration on each line, like this:
    p {

CSS Comments

  • Comments are used to explain your code, and may help you when you edit the source code at a later date.
  • Comments are ignored by browsers.
  • A CSS comment begins with "/*", and ends with "*/", like this:
  • /*This is a comment*/
    /*This is another comment*/