CSS Syntax

By Xah Lee. Date: .

CSS source code looks like this:

p {
 line-height:1.5;
 width:600px;
 font-family:sans-serif;
}

li {
 margin-top:10px;
 color:gray;
}

blockquote {
 color:blue;
}

img {
 border:solid thin black;
}

table.xyz {
 border:1px solid black;
}

In the above example, it says that any p tag's content (a paragraph) have a line height that's 1.5 times of default, and has a width of 600px [see CSS: Length Units] , and the font should be sans-serif. [see Common Web Fonts]

Similiarly, other HTML Tags 's appearance are also specified.

In general, CSS code has lines like this:

selector { property_name_1 : value_1; property_name_2 : value_2; property_name_3 : value_3; }

The selector basically means the tag matching syntax. It is technically called Selector .

Semicolon is used as separator, and is optional for the last item.

Space or line return has no meaning, unless they are inside a quoted string such as "Courier New".

code {font-family:"Courier New", monospace;}

CSS Basics


CSS

Basics

Selectors

Color

Font

Text Decoration

Box Model

Box Decoration

Layout

Layers

Transform/Animation

Line Wrap

Misc