This is the fifth major revision of the specification. It is on its way from a loose collection of ideas to an Internet-Draft, and we plan to finish by the end of 1995. We encourage programmers and authors to start experimenting with style sheets. Comments can be sent to the mailing list, or directly to the authors. For background material, see the resource page on HTML style sheets. Last changed: November 1, 1995

Cascading Style Sheets: fifth draft specification

Håkon W Lie (
Bert Bos (


  1. Background
  2. Overview
  3. Terminology
  4. Level 1 features
  5. Formatting model
  6. Level 1 properties
  7. Units
  8. Cascading order
  9. Aliases
  10. Formal grammar
  11. References
  12. Acknowledgments
  13. Appendix A: Sketches of level 2
  14. Appendix B: Suggested level 2 properties


HTML is a simple structural document format much used on the World-Wide Web. Web publishers commonly request more influence over the presentation of documents, and HTML is under constant pressure to add visual markup. Allowing publishers to attach style to documents will enhance the aesthetics of the web. Also, style enhances content: some publishers consciously choose colors and fonts based on the message they want to convey.

The web needs a mechanism that allows authors to influence the presentation while preserving the device-independence and document structure of HTML. There are four ways to do this: add new style elements to HTML, add new style attributes to existing HTML elements, resort to other formats (e.g. Postscript, PDF or GIF), or introduce style sheets. The first two alternatives will start a never-ending process of extending HTML to become a presentation language. Also, by not separating style and content they make it hard to apply different styles to the same content. The third alternative offers publishers more control by using presentation-oriented format. Sometimes control is important, but most requests for stylistic influence over text can be satisfied without leaving HTML. We think the fourth alternative, style sheets, is the best way to add style to the web.

Style sheets are very similar to the "templates" of desktop publishing applications. A simple style sheet might suggest that the headlines of a document are rendered in blue on a white background. By attaching style (color) to the structure of a document (headlines), style sheets ensure device-independence and the preservation of document structure. A style sheet can be stored separately from the document it applies to, and it is easy to change the presentation of a document by applying a different style sheet. Also, one style sheet can be applied to many documents.

HTML is an application of SGML [SGML], and the style sheet mechanism described in this specification is intentionally general enough to apply to any SGML DTD. For reasons of simplicity, all examples apply to HTML. The proposed style sheet mechanism has been developed in conjunction with HTML3 and closely matches its design guidelines.

While style sheets will open for publishers to add style to their documents, the reader should also be able to influence the presentation. Sometimes the output device on the reader's side needs special consideration (helvetica looks terrible on this screen!), sometimes personal handicaps requires special consideration (12 pt helvetica? I haven't been able to read that since I turned 80!), and readers may have their own aesthetical preferences (helvetica looks terrible on any screen). This proposal is called Cascading Style Sheets (CSS) for its ability to combine several style sheets from both readers and authors.


Publishers on the web do not request presentational control to the level of professional typography. Instead, they ask for influence over fonts, colors and space, and they want it now. In order to speed up the process of defining and implementing a style sheet mechanism on the web, levels have been introduced in this specification. Level 1 contains the most basic features of a style sheet mechanism, while retaining much of the expressive power. Level 2 will add new capabilities to the style sheet language, but all it is features haven't been worked out yet. Sketches of level 2 are included in the appendices.


the author of a document
the part of the UA's drawing surface onto which documents are rendered
Cascading Style Sheets, a style sheet mechanism defined in this document.
a property (e.g. "font-size") and a corresponding value (e.g. "12pt")
the designer of a style sheet
parsed SGML document. In technical terms, the document's ESIS (Element Structure Information Set).
SGML element
Hypertext Markup Language, an application of SGML. All style sheet examples in the CSS specification apply to HTML.
Hypertext Transfer Protocol.
a stylistic parameter that can be influenced through CSS. The CSS specification defines a list of properties
the person for whom the document is rendered
a declaration (e.g "font-family: helvetica") and its selector (e.g. "H1")
a string that identifies what elements the corresponding rule apply to. A selector can be based on the name of the element, existance and values of element attributes, and the context of the element.
Standard Generalized Markup Language, of which HTML is an application
style sheet
a collection of rules
User Agent. Often a "web browser" or "web client".
synonymous with "reader"

Level 1 features

Designing simple style sheets is easy. You only need to know a little HTML and some basic desktop publishing terminology. E.g., to set the text color of H1 elements to blue, you can say:
  H1 { color: blue }
The example consists of two main parts: selector (H1) and declaration (color: blue). The declaration has two parts, property (color) and value (blue). While the example above only tries to influence a small fraction of the properties needed for rendering an HTML document, it qualifies as a style sheet on its own. One of the fundamental features of CSS is that partial style sheets are combined into complete ones.

The selector is the glue between the HTML document and the style, and all HTML elements are possible selectors. HTML elements are defined in the HTML specifications, and the CSS specification only defines a syntax for how to address them. Also, the list of properties and values are defined in this specification.

Containment in HTML

In order for the style sheet to influence the presentation, the user agent (UA, often a "web browser" or "web client") must be aware of its existence. It is beyond this specification to define how HTML documents should link to style sheets. Also, CSS is not limited to HTML, but general to SGML. The example below is according to the HTML3 specification and the implemention in Arena, W3C's experimental browser.

  <LINK REL=STYLESHEET HREF="" TITLE="Bill's own style">
    H1 { color: blue }
The LINK element references an external style sheet, while the proposed STYLE element has a style sheet as content.

By declaring the NOTATION, the STYLE element can be used for other style sheet notations as well. For LINKed style sheets, the HTTP Content-Type field will declare the notation. The TITLE attribute assigns a name to a style sheet for user interaction purposes.

Typically, an organization-wide style sheet will reside in one location and be referenced through a LINK. The author may add document-specific style in the STYLE element. If conflicts arise, the rules inside STYLE will override those referenced through LINK.

A document can contain several LINK and several STYLE elements. The reader should be able to choose between several style sheets, e.g. through a pull-down menu with the names of all listed style sheets. STYLE elements without their own TITLE attribute are combined with the preceding titled style sheet following the normal cascading rules. If no preceding titled style sheet exists, the UA should assign a title to the style sheet and treat it as any other titled style sheet. If two style sheets have the same title, they should be combined using the normal rules for cascading.

CSS rules can possibly also be included in HTML attributes:

  <H1 STYLE="font-family: helvetica">Headline</A>
  <P STYLE="font: 12pt helvetica bold">Paragraph</A>


To reduce the size of style sheets, you can group selectors in comma-separated lists:
  H1, H2, H3 { font-family: helvetica }
Similarly, declarations can be grouped:
  H1 { 
       font-size: 12pt, 
       font-leading: 2pt, 
       font-family: helvetica, 
       font-weight: bold,
       font-style: normal
In addition, some properties have their own grouping syntax:
  H1 { font: 12pt/14pt helvetica bold normal }
which is equivalent to the previous example.


In the first example, the color of H1 elements was set to blue. Suppose we have an H1 element with an emphasized element inside:
  <H1>The headline <EM>is</EM> important!</H1>
Since no color has been assigned to EM, the emphasized "is" will inherit the color of the surrounding element, i.e. it will also appear in blue. Other style properties are likewise inherited, e.g. font family and size.

Inheritance starts at the oldest ancestor, i.e. the top-level element. In HTML, this is is the "HTML" element (although many HTML authors omit this tag). In order to set a "default" style property, you should use "HTML" as selector:

  HTML: color: dark-blue

Alternatively, the top-level element can be addressed as "*", e.g.:

  * { color: dark-blue }

The use of "*" to represent the top-level element is a CSS shorthand notation that is not limited to HTML.

Some style properties are not inherited from the parent to the child. In most cases, it is intuitive why this is not the case. E.g., the background property does not inherit. However, the parent element's background will shine through by default since the initial value is transparent.

Class as selector

To increase the granularity of control over elements, HTML3 introduces a new attribute: CLASS. Most elements can be sub-classed, and the subclass can be addressed in the style sheet:
    H1.punk { color: #00FF00 }
  <H1 CLASS: punk>Way too green</H1>

Classes can also be selectors independent of HTML elements:

    punk { color: green }
  <H1 CLASS = punk>Way too green headline</H1>
  <P CLASS = punk>Way too green paragraph</H1>
One interesting use of this feature is to introduce new elements without writing new style rules:
  <par class=p>This is a <emph class=em>PAR</emph>, which looks like a
  <tag class=strong>P</tag>, because it is declared as being of of the
  same class.</par>

Context sensitivity

Inheritance saves CSS designers a lot of typing. Instead of setting all style properties, you can create defaults and then list the exceptions. If you want to give EM elements within H1 a different color, you may specify:
  H1   { color: blue }
  EM   { color: light-blue }
When this style sheet is in effect, all emphasized sections, within or outside H1 will turn light-blue. Probably, you only wanted EMs within H1 to turn light-blue. You can specify this with:
  (H1) EM { color: light-blue }
The selector is now a search pattern. Only the last element of the search pattern is addressed (in this case the EM element), and only so if the search pattern matches. In the example above, the search pattern matches if EM is a descendant of H1, i.e. if EM is inside an H1 element.
  (LI) (LI) P      { font-size: small }    
  (LI) (LI) (LI) P { font-size: x-small }
Here, the first selector matches P elements with at least two LI ancestors. The second selector matches a subset of the first matches, i.e. P elements with at least three LI ancestors. The conflict is resolved by the second selector being more specific (due to the longer search pattern).

Search patterns can contain elements and/or classes:

  (P.reddish) punk  { color: red }
This selector matches all elements with subclass "punk" and an ancestor of element P and subclass "reddish".


Textual comments in a CSS style sheet start and end with two dashes:

  EM { color: red }  -- red, really red!! --

Level 1 ambitions

The CSS specification defines a list of style properties that a style sheet can influence. The goal is to be able to describe typography at the level of common desktop publishing. The following example, which includes a drop-cap initial and small-caps text, suggests the bounds of current properties:

   P { 
       text-effect: drop-cap,
       font-size: 12pt,
       alt-font-size: 24pt      -- assuming leading is zero --
   EM { font-style: small-caps }
  <P><EM>The first</EM> few words of an article in The Economist..
If an ASCII-based UA supports these properties (we do not expect them to), the above could be formatted as:
   | HE FIRST few words
   |of an article in the
The example shows the need for a new generic character-level element in HTML which doesn't bring with it any rendering conventions. We suggest adding a short HTML tag (e.g. "C") for this, but the definition is outside the scope of this specification.

The cascade

One of the features of CSS is that more than one style sheet can influence the presentation. There are two main reasons for this feature: modularity and balance.
a style sheet designer can combine several (incomplete) style sheets into one to reduce redundancy:
  @import ""

  H1 { color: red }     -- override imported sheet --

The @import .. statement is semantically equal to a <LINK REL=StyleSheet href= .. >. In case of a conflict, the imported style sheet has lower weight than the one from where it is being imported.

both readers and authors can influence the presentation through style sheets. To do so, they use the same style sheet language thus reflecting the philosophy of the web: everyone can become a publisher.

Typically, UAs will assume that the style sheets of your initial page (if it finds any) is your personal favorite, and apply them to all subsequent documents. If subsequent documents have their own style sheets, conflicts may arise. Conflict resolution is based on each style declaration having a weight. By default, the weights of the reader's declarations is less that the weights of declarations in incoming documents. I.e., if there are conflicts between the style sheets of an incoming document and the reader's personal sheets, the incoming declarations will be used.

Style sheet designers can increase the weights of their declarations:

  H1 { color: red ! important }
  P  { font-size: 12pt ! legal "IATA regulations" }
The ! legal .. construct is used if there are legal reasons behind the declaration, and the trailing string is a short reference to the statutes. "Important" and "legal" declarations have the same weight.

An important (or legal) reader declaration will override an incoming declaration with normal weight. An important (or legal) incoming declaration will override an important (or legal) reader declaration. A complete description of the cascading order can be found later in this specification.

The reference to the statutes should be displayed to the reader as a warning when the UA is not able to honor a legal declaration. The reader should acknowledge the warning with an action, e.g. a mouse click. Situations where the warning should be displayed include:

In some cases, it is clear from the context that the declaration cannot be honored and there is no need to warn the reader: One should also keep in mind that a UA may not be able to retrieve a style sheet pointed to by a LINK.

Anchor pseudo-classes

User agents commonly display newly visited anchors differently from older ones. Ideally, the style sheet mechanism should offer functionality to describe how and when anchors should change. This will be possible with the environment variables of level 2, but for level 1 we need to introduce pseudo-classes that can be used for addressing: { color: red }       -- unvisited link --
  A.visited { color: blue }   -- visited links -- { color: orange }  -- active links --

ID as selector

The HTML IS attribute has a unique value, and can therefore be of special importance as a style sheet selector:
  [ID="z098y"] { font-size = xx-large }
In level 2, any attribute can be a selctor using the same notation. ID is a an exception that is also allowed in level 1.

Formatting model

This document suggests a simple box-oriented formatting model. Each element that implies a line break (e.g. H1 and P, but not EM) is surrounded by a box. The size of the box is the sum of the formatted content (e.g. text or image), the box offset, and the margins. The background of the box is controlled with the background property, while the margins are transparent. The width of the margins specify the minimum distance to the edges of surrounding elements.

The following example with pseudo-constants shows how margins and box-offsets format:

      UL { 
           background: red, 
           margin: A B C D,      -- let's pretend we have constants in CSS --
           box-offset: E F G H   --                   "                    --
      LI { 
           background: blue, 
           color: white,         -- so text is white on blue --
           margin: a b c d,      -- let's pretend we have constants in CSS --
           box-offset: e f g h   --                   "                    --

      <LI>1st element of list
      <LI>2nd element of list
   |                                                        |
   |     A      UL margin (transparent)                     |
   |     _______________________________________________    |
   |  D |                                               | B |
   |    |    E   UL box-offset (red)                    |   |
   |    |    _______________________________________    |   |
   |    | H |                                       | F |   |
   |    |   |    a   LI margin (transparent,        |   |   |
   |    |   |        so red shines through)         |   |   |
   |    |   |    _______________________________    |   |   |
   |    |   | d |                               | b |   |   |
   |    |   |   |    e    LI box-offset (blue)  |   |   |   |
   |    |   |   |                               |   |   |   |
   |    |   |   | h  1st element of list      f |   |   |   |
   |    |   |   |                               |   |   |   |
   |    |   |   |    g                          |   |   |   |
   |    |   |   |_______________________________|   |   |   |
   |    |   |                                       |   |   |
   |    |   |     max(a, c)                         |   |   |
   |    |   |                                       |   |   |
   |    |   |    _______________________________    |   |   |
   |    |   |   |                               |   |   |   |
   |    |   | d |    e    LI box-offset (blue)  |   |   |   |
   |    |   |   |                               |   |   |   |
   |    |   |   | h  2nd element of list      f |   |   |   |
   |    |   |   |                               |   |   |   |
   |    |   |   |    g                          |   |   |   |
   |    |   |   |_______________________________|   |   |   |
   |    |   |                                       |   |   |
   |    |   |   c    LI margin (transparent,        |   |   |
   |    |   |        so red shines through)         |   |   |
   |    |   |_______________________________________|   |   |
   |    |                                               |   |
   |    |    G                                          |   |
   |    |_______________________________________________|   |
   |                                                        |
   |    C                                                   |

Technically, box-offset and margin properties are not inherited. But, as the example shows, the placement of a rendered element is relative to ancestors and siblings.

Horizontally, boxes inherit the width of the parent element (i.e. after the margin and box-offset have been deducted).

Vertically, all boxes are attached to the above box. Note that the above box doesn't necessarily contain the preceding HTML element. Since boxes are stacked vertically, some interesting effects can be achieved if sequential boxes don't end up on top of each other. In this way, "sideheads" and simple multiple-column layouts can be supported:

 |                                               |
 | (BODY margins & box)                          |
 |  ______________        _____________________  |
 | |              |;;;;;;|                     | | 
 | | (H1 box)     |;;;;;;| (P box)             | |
 | |              |;;;;;;|                     | |
 | | Headline...  |;;;;;;| While.the.paragraph | | 
 | |  |;;;;;;| | |
 | |______________|;;;;;;| continues.below.the | |
 | ;;;;;;;;;;;;;;;;;;;;;;| | |
 | ;;;;;;;;;;;;;;;;;;;;;;|_____________________| |
 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
   ^              ^      ^                     ^
   0%            35%    50%                   100%    
The above could be realized through:
  H1 { 
       margin-left: 0%, 
       margin-right: 65%   -- (100% minus 35%) --
  P  {
       margin-left: 50%, 
       margin-right: 0%
The percentages are relative to the width of the parent element.

Horizontal margins and width

Five properties influence the horizontal dimensions of an element: width, box-offset-left, box-offset-right, margin-left and margin-right. Added up, these have to be equal to the width of the parent element. Therefore, one cannot specify values for all properties and expect them to be honored. The relative strengths between them are as follows:
  1. box-offset-left
  2. box-offset-right
  3. width
  4. margin-left
  5. margin-right
By default, the value of the width property is "auto" which means it will be automatically calculated based on the other properties' values. However, if width is assigned another value, or the dimensions don't add up for other reasons, the property with the lowest rank will be assigned "auto".

Level 1 properties

Style sheets influence the presentation of documents by assigning values to style properties. This section lists the suggested style properties, and their corresponding units, of CSS level 1.

The list of level 1 properties has been kept to a to a minimum, while making sure commonly used styles can be expressed. Depending on the formatting model and the resources available, some properties can prove hard to incorporate into existing UA implementations (e.g. text-effect, text-style and break), and can be considered optional. [strengthen definition]

Also, an ASCII-based UA in a monochrome environment is not able to honor color values, but may try to lay out elements based on the style sheet properties.


Setting font properties will be among the most common uses of style sheets. Unfortunately, there exists no well-defined and widely accepted taxonomy for classifying fonts, and terms that apply to one font family may not be appropriate for others. E.g. "italics" is commonly used to label slanted text, but the term is not appropriate for sans-serif fonts (whose slanted fonts are called "oblique").

This specification suggests a liberal terminology for describing fonts, and a level of detail similar to common desktop publishing applications.


Value: <length> | <percentage> | <number> | xx-small | x-small | small | medium | large | x-large | xx-large
Initial: UA specific
Example: font-size: 12pt

Font sizes can either be set to an absolute height using "font-size", or to a relative index using "font-size-index". If defined, "font-size" will take precedence.

If the value is an integer number, it is to be interpreted as an index. Index 0 corresponds to "medium" (the actual size is application dependent and/or set-able by the user). A scaling factor of 1.44 is suggested between adjacent indexes, e.g. if the "medium" font is 10pt, the "large" font should be 12pt. (Perhaps a bigger scaling factor?). If the number is a floating point, the UA should interpolate a font size if possible. Otherwise, it should round off to the closest integer index.

Percentage is relative to the font-size of the parent element.

Note that an application may reinterpret an explicit size, depending on the context. E.g., inside a VR scene a font may get a different size because of perspective distortion.


Value: [ <family-name> | <generic-family> ]+
Initial: UA specific
Example: font-family: new-century-schoolbook serif

The value is a prioritized list of font family names and/or generic family names. List items are separated by white space and spaces in font family names are replaced with dashes.

In level 1, the following generic families are defined:

Style sheet writers are encouraged to offer a generic font family at the end of the list:

  font-family: univers helvetica sans-serif
Ideally, the style sheet writer should specify only one font, and the font manager should return the best alternative (perhaps by taking visual similarity, visual quality and performance into account). Unfortunately, current rendering environments do not offer this level of service, and it is beyond the style sheet mechanism to do so. Therefore, a prioritized list of alternative families can be supplied. This practice poses one problem: the UA must be able to determine if a font selection has been successful or not to know how far it should proceed in the list. One example: if the style sheet asks for "univers" and the window system is smart enough to suggest "helvetica" (which looks almost identical) as a replacement, is this a success or failure? This specification leaves the answer undefined for now.


Value: extra-light | light | demi-light | medium | demi-bold | bold | extra-bold | <number>
Initial: 0
Example: font-weight: demi-bold

Where extra-light = -3, light = -2, demi-light = -1, etc.

If the desired font weight is not available, the UA selects a substitution order. Non-integer font weights are allowed.


Value: italic | oblique | small-caps | normal
Initial: normal
Example: font-style: italic

If the preferred font style cannot be accomplished, the following substitutions should be attempted by the UA:

italic -> oblique
oblique -> italic
* -> normal

If "small-caps" are not available, capitals letter of a smaller font size can be used to render small characters if the resolution of the output medium is appropriate for this.


Value: <length> | <percentage>
Initial: UA specific
Example: font-leading: 20%

Leading refers to the extra space between lines. A percentage unit is relative to the font size. E.g.:

  P { font-leading: 20%, font-size: 10pt }
Here, the leading would be 2pt.


Value: size [ / line-height ] family [ weight ] [ style ]
Initial: not defined
Example: font: 12pt/14pt helvetica bold

This is a conventional shorthand notation from the typography community to set font-size, font-leading, font-family, font-style, and font-weight. Setting the properties individually override the shorthand notation if the weight is otherwise the same.

Note that it is the line height, not the leading, that is specified. The relationship is: line-height = font-size + font-leading.

Color and background


Value: <color>
Initial: UA specific
Example: color: #F00

See the section on units for a description.


Value: <color> | <uri> | transparent
Initial: transparent
Example: background: ""

This property does not inherit, but unless set explicitly the parent's background will shine through due to the initial transparent value.

If an image is found through the URI, it takes precedence over color. The color is used:


Value: [ repeat | x-repeat | y-repeat | norepeat | scroll | fixed ] + Initial: repeat scroll
Example: bg-style: x-repeat scroll

This property how the background image is laid out. By default, the background image is repeated in both x and y direction, and the image is scrolled along with the other content.



Value: <percentage>
Initial: 0
Example: text-spacing: 20%

Default text spacing is 0%. The UA is free to select text spacing algorithm.


Value: underline | overline | line-through | box | shadowbox | box3d | cartouche | blink | none
Initial: none
Example: text-decoration: underline

The list of possibilities may be kept short in a first version, it can always be extended later. Formatters should treat unknown values as `box' (a simple rectangle).

The color of the decoration is based on the color of the text.


Value: <number> | sub | super
Initial: 0
Example: text-position: -2


Value: capitalize | uppercase | lowercase | none
Initial: none
Example: text-transform: uppercase

"capitalize" uppercases the first character of each word.

"none" is used to neutralize an inherited value.


Value: initial-cap | drop-cap | alt-firstline | none
Initial: none
Example: text-effect: drop-cap

All text effects are rendered using the alternate properties.

the first alphabetical letter of the element is rendered using the alternate properties. There is no case conversion.
the first alphabetical letter of the element is rendered using the alternate properties and "dropped" into the box enclosing the paragraph.
the first line (as formatted by the UA) of the paragraph is rendered using the alternate properties.

Alternate properties

Some typographic styles require an alternate set of properties to be rendered. In level 1, this is the case for text-effect where the initial letter of the initial-cap and drop-cap values, as well as the first line of alt-firstline. In level 2 they will also be used for labels and inserted text before/after the element.

The following properties influence the "alternate" rendering:




See the formatting model for examples on how to use these properties.

box-offset-top, box-offset-right, box-offset-bottom, box-offset-left

Value: <length> | <percentage>
Initial: 0
Example: box-offset-left: 20%

How much space to insert between the border of the box and the content (e.g. text or image). See the formatting model for more on these properties.

Percentage values are relative to the width of the parent element.


Value: <length> | <percentage> [ <length> | <percentage> [ <length> | <percentage> [ <length> | <percentage> ] ] ]
Initial: 0
Example: box-offset: 20% 20%

The order is top, right, bottom, left. If there is only one, it applies to all sides, if there are two or three, the missing widths are taken from the opposite side.

The property is shorthand for setting "box-offset-top", "box-offset-right" "box-offset-bottom" and "box-offset-left" separately. The individual declarations take precedence if the weights are otherwise equal.

Percentage values are relative to the width of the parent element.

margin-left, margin-right

Value: <length> | <percentage> | auto
Initial: 0
Example: margin-left: 2em

The minimal horizontal distance between the element's box and surrounding elements.

Horizontal margins may be negative.

See the formatting model for a description of the relationsship between these properties and "width".

Percentage values are relative to the width of the parent element.

[Should we also be able to do margins relative to the width of the current element?]

margin-top, margin-bottom

Value: <length>
Initial: 0
Example: margin-top: 2em

The vertical space between two blocks of text is the maximum of all bottom margin and top margin specifications between the two. See the formatting model for an example.

Percentage values are relative to the width of the parent element. [rationale]

Vertical margins must be positive.


Value: <length> [ <length> [ <length> [ <length> ] ] ]
Initial: 0
Example: margin: 2em 1em

The four lengths apply to top, right, bottom and left respectively. If there's only one, it applies to all sides, if there are two or three, the missing lengths are taken from the opposite side.

The property is shorthand for setting "margin-top", "margin-right" "margin-bottom" and "margin-left" separately. The individual declarations take precedence if the weights are otherwise equal.


Value: block | inline
Initial: undefined
Example: break: block

This property decides if an element is block-level (e.g. H1 in HTML) or inline (e.g. EM in HTML). For HTML documents, the initial value will be taken from the HTML specification.

This property is not inherited.


Value: left | right | center | justify
Initial: human language dependent
Example: align: center

This property describes how text is aligned. It applies only to elements that have a break before them.


Value: <length> | <percentage>
Initial: 0
Example: indent: 3em

This property is not inherited.

Extra indent to apply to the first line only. May be negative (`outdent'). Only applies if the element starts a paragraph (either because it implies a break itself, or because it happens to follow a break.) An indent is not inserted in the middle of an element that was broken by another (such as BR in HTML).

Percentage values are relative to the width of the parent element.


Value: <length> | auto | <percentage>
Initial: auto
Example: width: 100pt

This property can be applied to text, but it is most useful with inline images and similar insertions. The width is to be enforced by scaling the image if necessary. When scaling, the aspect ration of the image should be preserved (unless the height, a level 2 property, is declared non-auto).

Percentage values are relative to the width of the parent element.

See the formatting model for a description of the relationsship between this property and "margin-left" and "margin-right".


Value: float-left | float-right | normal
Initial: normal
Level: 2
Example: display-area: float-left With the value "normal", the element will be displayed in the main text. "float-left" and "float-right" will make the element float to the margin. This property is often used with inline images.


The page properties are used for paged media, e.g. paper and page-oriented screen browsers.

page-break-after, page-break-before

Value: <number> | never | discourage | neutral | encourage | always
Initial: 0
Example: H1 { page-break-after: -2 }

Numbers can be from -2 to 2, corresponding, respectively, to the keywords. All "pagebreak-before" and "pagebreak-after" values that apply between two elements are combined according to the following table:

	  |-2 -1  0  1  2
	-2|-2 -2 -2 -2  2
	-1|-2 -1 -1  1  2
	 0|-2 -1  0  1  2
	 1|-2  1  1  1  2
	 2| 2  2  2  2  2
In algorithmic terms: take the one with the largest absolute value; if they are the same, use the positive value.


Value: <number> | never | discourage | neutral
Initial: 0
Example: PRE { page-break-inside: discourage }

Values can be -2, -1 or 0 meaning, respectively, never allow page-break inside element ("never"), discourage page-break inside element ("discourage"), or neutral about page-break inside element ("neutral").



  inches (in)
  pixels (px)
  centimeters (cm)
  millimeters (mm)
  ems (em)            -- the width of the character 'M'       --
  ens (en)            -- half the width of an em              --
  points (pt)
  characters (ch)     -- should be dropped in favor of ems?   --
  picas (pc)


In most cases, a percentage unit is relative to a length unit. text-spacing is an example of a property that is not relative to a lenght unit.


A color is a either a color name, 3-tuple or a hex-color. A short list of supported color names should be added, e.g., black, white, red, green, blue, yellow, cyan, magenta, pink, brown, gray, orange, purple, turquoise, violet. Also, prefixing color names with "light-" or "dark-" is allowed, e.g. "light-blue" and "dark-gray".

The RGB color model is being used in color specifications. Other color models should be kept in mind for later extensions.

Different ways to specify red:

  EM { color: #F00 }
  EM { color: #FF0000 }
  EM { color: 255 0 0 }      -- integer range: 0-255   --
  EM { color: 1.0 0.0 0.0 }  -- float range: 0.0 - 1.0 --
  EM { color: red }


A Uniform Resource Identifier (URI) should be enclosed in quotes:

  BODY { background: "" }
Partial URIs are interpreted relative to the source of the style sheet, not relative to the document.

Cascading order

Conflicting rules are intrinsic to the CSS mechanism, and should be resolved in the following manner:

  1. Reduce rules with identical selectors setting the same property. If the rules differ in imported -level, the least imported should live, while the other rules are discarded. Then, if there still are rules with identical selectors setting the same property, the one specified last should live, while the others are discarded.
  2. Find all declarations that apply to the element in question.
  3. Sort the declarations by explicit weight: declarations marked "!important" or "!legal .." are heavier than unmarked (normal) declarations.
  4. Sort by origin: incoming style sheets override the reader's style sheet.
  5. Sort by specificity of selector: the "longer" the selector, the more specific it is. The exact definition of "length" is no yet clear, but intuitively, this holds:
      "*" < "LI" < "(UL) (OL) LI" < "(UL) (OL)".
  6. Resolve conflicts between properties: individual declarations will override compound declarations. E.g, setting margin-left will override the setting of the left margin in the margin property.
  7. Sort by order specified: if two rules still have the same weight, the latter specified should live.

The search for the property value can be terminated whenever one rule has a higher weight than the other rules who apply to the same element.

This strategy gives incoming style sheets considerably higher weight than those of the reader. It is therefore important that the reader has the ability to turn off the influence of style sheets, e.g. through a pull-down menu.


Some terms may have spellings in different traditions. The following aliases should be accepted:

color  : colour
italic : italics

Formal grammar

This is the grammar for CSS. It consists of two parts: a context free grammar in Yacc/Bison format and a lexical analyzer in Lex/Flex format. The formal grammar supports both level 1 and level 2. Although level 1 grammar is a little simpler, we encourage implementation to parse style sheets of both levels.

Yacc/Bison grammar

%expect 2
   There are two shift/reduce conflicts in more_terms,
   because op can be empty



 : imports defs rules
 : imports IMPORT url
 | /* empty */
 : defs constant_def
 | defs archform_def
 | /* empty */
 : DEFINE unique_id '=' value ';'
 : ARCHFORM attrname
 : rule_seq media_rules
 : media_rules medium rule_seq
 | /* empty */
 : ':' IDENT other_media ':'
 : other_media '&' IDENT
 | /* empty */
 : rule_seq rule
 | /* empty */
 : selector_seq '{' declaration_seq '}'
 : selector_seq ',' selector
 | selector
 : toplevel
 | ancestors predecessor_opt elemspec
 : '*'
 : ancestors predecessor_opt ancestor
 | /* empty */
 : '(' elemspec ')'
 : predecessor
 | /* empty */
 : '/' elemname '/'
 : elemname attrspec_seq
 | attrspec_seq
 : attrspec_seq attrspec
 | /* empty */
 : '[' attrname constval_opt ']'
 : '=' constval
 | /* empty */
 : declaration_seq ',' declaration
 | declaration
 : property ':' value priority_opt
 | property op_eq value priority_opt
 | /* empty */

 * Operator precedence: high to low
 * 5:  + -      (monadic plus, monadic minus)
 * 4:  * / %    (multiply, divide, remainder)
 * 3:  + -      (plus, minus)
 * 2:  << >>    (interpolate low, interpolate high)
 * 1:           ([=space] concatenate)
 : value1 value
 | value1
 : value2 INTERPOLATELO value1
 | value2 INTERPOLATEHI value1
 | value2
 : value3 '+' value2
 | value3 '-' value2
 | value3
 : value4 '*' value3
 | value4 '/' value3
 | value4 '%' value3
 | value4
 : '+' term
 | '-' term
 | term
 | EMS
 | attref
 | envref
 | '(' value ')'
 : '[' attrname ']'

Lexical scanner

#include ""
#include "constants.h"
    The constants include definitions similar to the following:

    #define WEEK (7 * DAY)
    #define DAY (24 * HOUR)
    #define HOUR (60 * MINUTE)
    #define MINUTE (60 * SECOND)
    #define SECOND 1
    #define INCH (25.4 * MM)
    #define CM (10 * MM)
    #define MM 1
    #define PICA (12 * INCH/72 * MM)
    #define POINT (INCH/72 * MM)

%a 3000
%o 4000

urlchar         [a-zA-Z0-9:/_%~!@#$?*+{};.,|=`'-]
d               [0-9]
notnm           [^a-zA-Z0-9-]
nmchar          [a-zA-Z0-9-]|\\\.
nmstrt          [a-zA-Z]
w               [ \t\n]*
num             {d}+|{d}*\.{d}+
h               [0-9a-fA-F]
hexcolor        #{h}{h}{h}|#{h}{h}{h}{h}{h}{h}|#{h}{h}{h}{h}{h}{h}{h}{h}{h}
ident           {nmstrt}{nmchar}*



"--"                    {BEGIN(COMMENT);}

<COMMENT>"--"           {BEGIN(INITIAL);}
<COMMENT>\n             {/* ignore */}
<COMMENT>.              {/* ignore */}

@import                 return IMPORT;
@archform               return ARCHFORM;
@define                 return DEFINE;
"!"{w}legal             {return LEGAL;}
"!"{w}important         {return IMPORTANT;}
"$"{ident}              {return ENVVAR;}
{hexcolor}              {return HEXCOLOR;}
{ident}                 {return IDENT;}
\"[^"\n]*\"             |
\'[^'\n]*\'             {yylval.str = noquotes(yytext); return STRING;}
{num}                   {yylval.num = atof(yytext); return NUMBER;}
{num}{w}"%"             {yylval.num = atof(yytext); return PERCENTAGE;}
{num}{w}pt/{notnm}      {yylval.num = atof(yytext) * POINT; return LENGTH;}
{num}{w}mm/{notnm}      {yylval.num = atof(yytext); return LENGTH;}
{num}{w}cm/{notnm}      {yylval.num = atof(yytext) * CM; return LENGTH;}
{num}{w}pc/{notnm}      {yylval.num = atof(yytext) * PICA; return LENGTH;}
{num}{w}inch/{notnm}    {yylval.num = atof(yytext) * INCH; return LENGTH;}
{num}{w}px/{notnm}      {yylval.num = atof(yytext) * pixelwd; return LENGTH;}
{num}{w}em/{notnm}      {yylval.num = atof(yytext); return EMS;}
{num}{w}ch/{notnm}      {yylval.num = atof(yytext); return NCHARS;}
{num}{w}d/{notnm}       |
{num}{w}day/{notnm}     |
{num}{w}days/{notnm}    {yylval.num = atof(yytext) * DAY; return NUMBER;}
{num}{w}w/{notnm}       |
{num}{w}week/{notnm}    |
{num}{w}weeks/{notnm}   {yylval.num = atof(yytext) * WEEK; return NUMBER;}
{num}{w}h/{notnm}       |
{num}{w}hour/{notnm}    |
{num}{w}hours/{notnm}   {yylval.num = atof(yytext) * HOUR; return NUMBER;}
{num}{w}m/{notnm}       |
{num}{w}min/{notnm}     |
{num}{w}minute/{notnm}  |
{num}{w}minutes/{notnm} {yylval.num = atof(yytext) * MINUTE; return NUMBER;}
{num}{w}s/{notnm}       |
{num}{w}sec/{notnm}     |
{num}{w}second/{notnm}  |
{num}{w}seconds/{notnm} {yylval.num = atof(yytext) * SECOND; return NUMBER;}

"<<"                    return INTERPOLATELO;
">>"                    return INTERPOLATEHI;
"+:"                    return PLUS_EQ;
"-:"                    return MINUS_EQ;
"*:"                    return STAR_EQ;
"/:"                    return SLASH_EQ;
":"                     return ':';
"."                     return '.';
"/"                     return '/';
"*"                     return '*';
"+"                     return '+';
"-"                     return '-';
"="                     return '=';
"("                     return '(';
")"                     return ')';
"{"                     return '{';
"}"                     return '}';
"["                     return '[';
"]"                     return ']';
";"                     return ';';
"&"                     return '&';
","                     return ',';
[ \t]+                  {/* ignore whitespace */}
\n                      {/* ignore whitespace */}

.                       {yyerror("Illegal character");}


ISO 8879. Information Processing - Text and Office Systems - Standard Generalized Markup Language (SGML), 1986.


During the short life of HTML, there have been several style sheet proposals to which this proposal is indebted. The following people's proposals have been influential:

Through and other electronic media, these people have contributed: Also, thanks to Tim Berners-Lee, Vincent Quint, Cécile Roisin, Irène Vatton, Phill Hallam-Baker, Terry Allen and Jon Smirl for constructive discussions. A special thanks goes to Dave Raggett for his encouragement, suggestions and work on HTML3.

Appendix A: Sketches of level 2

In level2, the values of level 1 turn into expressions, and the addressing scheme is extended.

Attribute-based addressing

The CLASS attribute has been added to the HTML3 specifications with style sheets in mind, and enjoys a special shorthand notation as described above. Also, other attributes/values be used in addressing:
  A[HREF] { color: red }          -- the HREF attribute exists --
  H1[CLASS = huge] { font-size: 60pt } -- another way of writing H1.huge --

Sequential patterns

Level 1 contains functionality for addressing elements based on its ancestors. In level 2, one can also address based on siblings. A typical example is making the first paragraph after a headline bold:

  /H1/ P { font-weight: bold }
The '/' indicates the start of a sequential pattern search. All property declarations are performed on the last element of the search pattern.

Combined with the hierarchical search patterns, one has powerful context-sensitive addressing:

  H1                  -- every H1
  H1, H2              -- every H1 and every H2
  (H1) EM             -- EM inside H1
  (DIV) (H1) EM       -- EM inside H1 inside DIV
  /H1/ P              -- P that immediately follows H1
  (DIV) /H1/ P        -- P that immed. follows H1 inside DIV
  (DIV) /H1/ (P) EM   -- EM inside P that immed. follows H1 inside DIV
  // P                -- P that follows nothing (i.e., P that is 1st child)
  (DIV[CLASS=CHAP]) P -- P inside DIV with CLASS=CHAP
Note that the last example could have been written (DIV.chap) P.

Multiple media

Could one come up with a simple set of binary conditions to describe an output medium. How about:

Then, conditional rules could look like:
  :hires & color & bitmap:
    H1 { font-size: 4 }

    H1 { font-size: 24pt }

    h1 { font-size: 60pt }

Constraints and environment variables

[interesting, but potentially complex issue]

The following environment variables are available for use in style sheets:

The following two are only defined inside an element that contains a hyperlink: One could then change the color of a hyperlink with:
  a[href] { color: dark-red << $LASTVISIT/30d >> dark-blue }
The combination of constraints and environment variables can be quite interesting. Set the left margin to be 1/10 of the window width, but always more than 2em and less than 20em:
  * { margin-left:  2em << $WIDTH/10 >> 20em }
Let the color of the background fade from white to yellow as the document ages. After two days (2d), the fading process is complete:
  * { background: white << $AGE/2d >> yellow }
Let the color of text links change from red to blue as the document loads:
  * { text-link: red << $FETCHED >> blue }

Addressing environment properties

[This section is under fire. Among the strongest charges against it is the possible introduction of asymmetry ("the user can do this, but not the author"). If you would like to see it survive, you should voice your opinion.]

While the main focus of this specification is to define a standard for attaching style to HTML, the users' WWW browsing environment has additional elements. Applications have a user interface, they show you the HTML source on request, and GUI clients have a window size. While one normally would leave user preferences to the application and a configuration file, the notion of cascading style sheets has the potential of addressing all issues of style through one interface. The user's personal style sheet can be used to set the fonts of the browser buttons as well as incoming documents' H1 elements. Authors should be careful when trying to influence environment properties, and clients could choose to ignore them.

It is important to syntactically mark the difference between style properties of the environment and HTML elements. One should be careful when picking names. Here are some possibilities:

  $HTML-SOURCE { font-family: courier, font-size: 12pt }
  $CLIENT-WINDOW { width: 600px, height: 800px }
  $CLIENT-WINDOW { font-family: helvetica }
  $HTML_ERROR { color: yellow, background: red }
An initial '$' marks environment elements.


  @define myred = 0.8, 0.1, 0.1

[Should one define a lexical macro, as in C, or a symbolic constant, as in Pascal?]

[What if "myred" has different definitions in various style sheets?]


Addition, subtraction, multiplication and division are supported.

Relative values

Ideally, one should be able to refer to other elements' values in expressions. Since values may be context-dependent, they could be hard to find.
  h2 { font-size: h1[font-size] * 0.8 }
  P { font-size:[font-size] - 12 pt }
Instead, one may rephrase expressions in terms of either the inherited property or a symbolic constant. In either case, no special syntax is required:
  font-size: font-size - 12pt       -- relative to inherited size
  color: myred                      -- relative to constant

Appendix B: Suggested level 2 properties

Level 2 properties are a superset of level 1.

New values to existing level 1 properties


block-before | block-after | line-before | line-after


Suggested new properties

border-style (or box-style)

Value: none | normal | raised | lowered | beveled | etched | shadow
Initial: none
Level: 2
Example: border-style: normal

This property is not inherited. If UL has a border around it, you don't want each LI inside to inherit this border.

Additional possibilities include: single, double, thin-thick, thick-thin, dotted, wavy, baroque, filet, art-deco.

[Perhaps `border' should be changed to `box', because of the proposed box-background (see below) and because it is shorter. Disadvantage is that box-width sounds less natural. I believe both are equally accepted terms in the printing industry.]

border-width (or box-width)

Value: <width> [ <width> [ <width> [ <width> ] ] ]
Initial: medium
Level: 2
Example: border-width: thick thin

A width is either a length or one of the keywords `thin', `medium' or `thick'. The four widths apply to top, right, bottom and left respectively. If there's only one, it applies to all sides, if there are two or three, the missing widths are taken from the opposite side.

The box is drawn inside the space set by the margins.

border-color (or box-color)

Value: <color> | <uri>
Initial: inherited (init: appl. dep.)
Level: 2
Example: border-color: "";

URL must point to an image, which is tiled around the border.

border-background (or box-background)

Value: <color> | <uri>
Initial: none
Level: 2
Example: border-background: yellow

A new one. I thought that maybe it wasn't such a good idea to let background do double duty. If this is accepted, then border-style `none' means: neither border nor background.


Value: <display-type> [ <string> ]
Initial: normal
Level: 2
Example: display: note map

How to display the content. The display-type can be:

Paged and scrolling media should interpret these as best they can, e.g., note could become a footnote.

The string after the keyword is a hint for the label of the button (if any). It follows the syntax of insert-before, so that "note map" causes an button to be inserted with the map entity from the WWW icons.


Value: <uri> | none
Initial: none
Level: 2
Example: replace: {SRC}

Replace the element with a rectangle that contains the document that the URL points to. Usually applied to inline images (IMG or FIG).


Value: <length> | auto
Initial: undefined
Example: height: 50pt

Only applies to inline images and other insertions.

For images, the width is to be enforced by scaling the image if necessary.

insert-before, insert-after

Value: <string>
Initial: ""
Level: 2
Example: insert-before: "title: "

Uses alternate properties. Note that the string can be an expression:

  insert-before: caution " class = " {CLASS} 1em

This is a concatenation of a symbol entity `caution', a string, an attribute value and 1em of whitespace.

The concatenation operator is implicit. Keywords in the expression can be either entity names (ISO character entities or WWW symbol entities), properties of type length (such as margin-left), or other properties. Entities are replaced by their symbol, lengths are replaced by that amount of horizontal whitespace, non-length properties are converted to a string. Sub-expressions of type length are evaluated and converted to that amount of whitespace.

Various non-sorted properties

List Numbering

 * { numbering: on | off }
 * { number-style: arabic | lower-roman | upper-roman | lower-alpha | upper-alpha }
 * { number-inherit: on|off }

[Needs some work, level 2 issue?]


[Level 2 issue]


[Level 2+ issue]