Posted in All Posts, Semester 2

CSS Syntax

For any programming language, correct syntax is very important to code.
CSS Syntax contains of a set of special symbols called rules.

A rule consists of two parts:
» Selector : It is the part before the  curly braces.
» Declaration : It is the part within the curly braces.

A declaration has two parts separated by a colon:
» Property : Refers to the part before the colon.
» Value : It is the part after the colon, it should be followed by a semi-colon.

Eg. h1{color:green;}
So here we have,

  1. Selector = h1
  2. Declaration = color: green
    • Property = color
    • Value = green

You may want to add more than one declarations for one selector. Declarations can be grouped together for one selector in CSS as shown below.

Any text in p tag will be red and will have Arial font.

If you want to get same styles in different selectors, this can be also done in CSS as shown below,
h1, h2, h3{color: blue; text-align: right;}
Now all text in h1, h2 and h3 will be blue and aligned to right.

We hope that you found this article to be helpful.
Please share your thoughts in the Comments Section.

If you liked this article, then please like our Facebook page.

See Comments, Class & ID Selectors in CSS.

Suggested Reading

Comment your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.