CSS Syntax
Examples
CSS Examples
A CSS rule consists of two main parts: a selector, and one or more declarations:
The selector is usually the HTML element you need to style.
Each declaration consists of a property and a value.
The property is the style attribute you want to set. Each property has a value. The property and value are separated by a colon.
CSS Examples
A CSS declaration always ends with a semicolon ;
, and declarations are enclosed in curly braces {}
:
p {color:red;text-align:center;}
For better readability, you can describe one property per line:
Example
p
{
color:red;
text-align:center;
}
CSS Comments
Comments are used to explain your code and can be edited as needed; browsers ignore them.
CSS comments start with /*
and end with */
, as shown in the example below:
Example
/* This is a comment */
p
{
text-align:center;
/* This is another comment */
color:black;
font-family:arial;
}