Cascading Style Sheets/Syntax

Cascading Style Sheets are most often linked to a web page so that they can be used in an entire site. Because of this they are an independent file and have their own construction.

A stylesheet should begin with a declaration.

After this declaration each CSS rule is independent and made of three parts: a selector, a property and an argument (i.e. a value):

Example:

What this breaks down to here is this:

Each selector can have as many properties as you would like. The properties and values are enclosed in { } tags.

Rules
CSS rules are preceded by the symbol and are often the start of blocks of code. Rules take at least 1 argument. Some examples of rules are, for defining the document character set; , for setting properties for a type of media, often , and ; and  for setting up a web font.

Selectors
Selectors are where most of the power in CSS lies. Selectors allow the author to specifically target an element to apply any given property to. Many different selector types can be combined for the precision application of styles.

Elements
Elements that are specified in CSS definitions (abbreviated E, F, etc.) correspond to the (X)HTML or XML elements in the document. In HTML or XHTML, common elements include,  , and. In XML, the element names will vary with the type of document to be displayed.

Class
Class is the most basic of the selectors. The class operator is a " " and the syntax is.

ID
ID specifies a unique element in the document and in (X)HTML it is also the fragment identifier. The ID operator is a " " and the syntax is.

Attribute
Attribute selection is a newer feature in CSS that allows selection based on any attribute of the element. The syntax is. Attribute supports several different matching operators, including,  ,  ,   and.

Pseudo-class
Pseudo-classes are special classes based on the state of an element and uses the  operator. The syntax is. Commonly used pseudo-classes include,   and  ...

Blocks
Blocks of code are everywhere in CSS. A block is started with  and closed with. Blocks are used to group CSS statements into logical groups based on the author's needs. Blocks are most commonly used by Rules and to group properties to a selector.

Properties
Properties are the meat of CSS. The syntax is quite simple,. Properties are always after a selector and always inside a  block. A property must be ended with a  to close it.

CSS/Regole e sintassi