In computing, Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in a markup language. Its most common application is to style web pages written in HTML and XHTML, but the language can be applied to any kind of XML document, including SVG and XUL. The CSS specifications are maintained by the World Wide Web Consortium (W3C). In order to maintain standards compliance, it is recommended that CSS code is validated before release.
CSS is used by both the authors and readers of web pages to define colors, fonts, layout, and other aspects of document presentation. It is designed primarily to enable the separation of document content (written in HTML or a similar markup language) from document presentation (written in CSS). This separation can improve content accessibility, provide more flexibility and control in the specification of presentational characteristics, and reduce complexity and repetition in the structural content. CSS can also allow the same markup page to be presented in different styles for different rendering methods, such as on-screen, in print, by voice (when read out by a speech-based browser or screen reader) and on braille-based, tactile devices. Similarly, identical HTML or XML markup can be displayed in a variety of styles, 'brands', liveries or colour schemes by using different CSS.
CSS information can be provided by various sources:
CSS specifies a priority scheme to determine which style rules apply if more than one rule matches against a particular element. In this so-called 'cascade', priorities or 'weights' are calculated and assigned to rules, so that the results are predictable.
- · Author styles (style information provided by the web page author), in the form of
- · external stylesheets, i.e. a separate CSS-file referenced from the document
- · embedded style, blocks of CSS information inside the HTML document itself
- · inline styles, inside the HTML document, style information on a single element, specified using the "style" attribute.
- · User style
- · a local CSS-file specified by the user using options in the web browser, and acting as an override, to be applied to all documents.
- · User agent style
- · the default style sheet applied by the user agent, e.g. the browser's default presentation of elements.
Advantages of using CSS include:
CSS has a simple syntax, and uses a number of English keywords to specify the names of various style properties.
- · Presentation information for an entire website or collection of pages can be held in one place, and can be updated quickly and easily.
- · Different users can have different style sheets: for example a large text alternative for visually-impaired users, or a layout optimised for small displays for mobile phones.
- · The document code is reduced in size and complexity, since it does not need to contain any presentational markup.
A style sheet consists of a list of rules. Each rule consists of one or more comma-separated selectors and a declaration block. A declaration-block consists of a list of semicolon-separated declarations in curly braces. Each declaration itself consists of a property, a colon (:) then a value.
Take a look at CSS Standards for other learning possiblities about CSS