CSS (source code)
= CSS
{c}
<CSS>, short for Cascading Style Sheets, describes the presentation of structured documents such as <HTML> pages. A <CSS selector> identifies elements to which a rule applies; a <CSS declaration> assigns a property and value. The <CSS cascade> resolves competing declarations, while some properties can inherit values from an element's parent.<Assigning property values, Cascading, and Inheritance in CSS 2.2 by W3C>[Chapter 6, opening property-assignment description; §§6.2 and 6.4, inheritance and cascade]{ref}
For example, consider the rules `p { color: blue; }` and `.warning { color: red; }`. A paragraph with `class="warning"` matches both <CSS selectors>. For these ordinary rules in the same styling context, the class selector has greater <CSS specificity> than the element selector, so the paragraph is red even if the blue rule is written later. A <CSS cascade> therefore does more than choose whichever declaration was encountered last.<Assigning property values, Cascading, and Inheritance in CSS 2.2 by W3C>[§6.4.1, cascading order; §6.4.3, selector-specificity calculation]{ref}
If a child element supplies no overriding color, it can inherit the paragraph's red color. That does not mean every property is inherited: properties define their own inheritance behavior. A width declaration such as `width: 200px` also concerns layout in <CSS pixels>; it does not promise a width of 200 physical display <pixels>.<CSS Values and Units Module Level 3 by World Wide Web Consortium>[§5.2, absolute lengths and distinction between reference and device pixels]{ref}
Keeping document structure in <HTML> and presentation in <CSS> allows the same content to receive different screen or print styling. The rules describe the desired presentation; the browser determines the layout and rendered image from the document, styles and output device.
Back to article page