CSS Syntax


Example


CSS Examples

CSS rules consist of two main parts: selectors, and one or more declarations:

Selectors are usually the HTML elements whose style you need to change.

Each declaration consists of a property and a value.

Property is the style attribute you wish to set. Each property has a value. Properties and values are separated by a colon.


CSS Examples

CSS declarations always with a semicolon;end; declarations always with curly braces{}Enclose:

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

To make CSS more readable, you can describe only one property per line:

Example

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

Try it Yourself »


CSS Comments

Comments are used to explain your code, and you can edit them freely; the browser will ignore them.

CSS comments begin with/*Start with*/end, as in the following example:

Example

/*This is a comment*/ p { text-align:center; /*This is another comment*/ color:black; font-family:arial; }
other extensions