Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in HTML or XML. CSS is a core language of the open web and is standardized across Web browsers according to W3C specifications.
A style sheet consists of rules where each rule consists of one or more selectors, and a declaration block.
selector {
// Declaration block
}
A declaration block consists of a list of declarations in braces where each declaration consists of a property, a colon (:
), and a value. Multiple declarations require a semi-colon (;
) to separate each declaration.
selector {
property-a: value;
property-b: value;
}
For example:
body {
color: white;
background-color: black;
}
CSS selectors define the elements to which a set of CSS rules apply.
Universal:
Type:
Class:
ID:
Attribute:
Pseudo class:
Pseudo element:
Selector list:
Descendant combinator:
Child combinator:
General sibling combinator:
Adjacent sibling combinator:
Column combinator:
By default, a web browser serves documents using minimal formatting handled by user agent style sheets. Because there is no cross-browser standard for user agent styles, it may be desirable to leverage the cascade in order to normalize or reset these styles.
Implementing a common design methodology can increase the scalability, maintainability, and optimization of CSS. Popular methodologies include: