Cascading Style Sheets allow designers to precisely control various attributes of their documents, but also allow users to continue to effect certain attributes.
Styles are defined in either the header of a document, in specific HTML tags, or in a separate document which can be referenced by multiple HTML pages. Styles can inherit properties from one another -- thus, the description of them as being cascading.
CSS relies on fonts which are installed on the user machine. However, there are some complications, namely that system fonts and font sizes are not the same for Mac and Windows.
Basic syntax of CSS
The basic mechanics of CSS includes the following components: selectors, declarations, and properties.
Here h2 is the selector, color is a declaration, and red is a property.
The example below shows one simple way to reference a style, where the style is declared in the header of a document. Each example of the h2 tag will appear red in a browser which supports CSS.
Declarations can be grouped, as follows:
In addition to declaring tags, "classes" can be defined. "Classes" are indicated by a period (.) that precedes them.
Stylesheets can be invoked through a link statement to a global stylesheet.
The content of mystyles.css may look somethings like this:
The above stylesheet examples use "identifiers" indicated by the pound sign (#) and "classes" which are indicated by the period (.) that precedes them.
The HTML page that references the stylesheet can then use the identifiers and classes in combination, by using the DIV tag.
Stylesheets can also be used to control colors and images. For example: