CSS Syntax


Examples


CSS Examples

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

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

Selectors are usually HTML elements that you need to change styles.

Each declaration consists of a property and a value.

The property is the style attribute you want to set. Each property has a value. properties and values are separated by colons.


CSS Examples

CSS declarations always end with a semicolon (;), and declarations are always enclosed in curly braces ({}):

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

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

Example

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

 Try It! 


CSS Comments

Comments are used to explain your code, and you can edit it at will, the browser will ignore it.

CSS comments start with /* and end with */ , examples are as follows:

Example

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