CSS

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.

Syntax

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;
}

Selector

CSS selectors define the elements to which a set of CSS rules apply.

Basic

Universal:

Type:

Class:

ID:

Attribute:

Pseudo

Pseudo class:

Pseudo element:

Grouping and combining

Selector list:

Descendant combinator:

Child combinator:

General sibling combinator:

Adjacent sibling combinator:

Column combinator:

Property

Priority

Specificity

Inheritance

User agent style sheets

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.

Style sheet resources

Methodologies

Implementing a common design methodology can increase the scalability, maintainability, and optimization of CSS. Popular methodologies include:

Methodologies resources

Preprocessors

Extension languages

CSS in JavaScript