W3C WD-css1-960911

Cascading Style Sheets, level 1

W3C Working Draft 11-September-96

This version:
Håkon Wium Lie (howcome@w3.org)
Bert Bos (bert@w3.org)

Status of this document

This document is part of W3C (http://www.w3.org/) activities in the areas of HTML, Style Sheets, Fonts and Graphics.

This is a W3C Working Draft for review by W3C members and other interested parties. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to use W3C Working Drafts as reference material or to cite them as other than "work in progress". A list of current W3C technical reports can be found at http://www.w3.org/pub/WWW/TR. Since working drafts are subject to frequent change, you are advised to reference the latter URL, rather than the URL for this working draft.


This document specifies level 1 of the Cascading Style Sheet mechanism (CSS1). CSS1 is a simple style sheet mechanism that allows authors and readers to attach style (e.g. fonts, colors and spacing) to HTML documents. The CSS1 language is human readable and writable, and expresses style in common desktop publishing terminology.

One of the fundamental features of CSS is that style sheets cascade; authors can attach a preferred style sheet, while the reader may have a personal style sheet to adjust for human or technological handicaps. The rules for resolving conflicts between different style sheets are defined in this specification.

Comments to this draft can be sent to the www-style@w3.org mailing list, or directly to the authors. For background material, see the resource page on web style sheets [1]. We encourage browser vendors to start implementing CSS1.

Table of contents


1         Basic concepts
1.1         Containment in HTML
1.2         Grouping
1.3         Inheritance
1.4         Class as selector
1.5         ID as selector
1.6         Contextual selectors
2         Pseudo-classes and pseudo-elements
2.1         Anchor pseudo-classes
2.2         Typographical pseudo-elements
2.3         The 'first-line' pseudo-element
2.4         The 'first-letter' pseudo-element
2.5         Pseudo-elements in selectors
2.6         Multiple pseudo-elements
3         The cascade
3.1         'important'
3.2         Cascading order
4         Formatting model
4.1         Vertical formatting
4.2         Horizontal formatting
4.3         Lists
4.4         The canvas
4.5         Floating elements
4.6         Replaced elements
4.7         The height of lines
4.8         'BR' elements
5         CSS1 properties
5.1         Notation for property values
5.2         Font properties
5.2.1         Font matching
5.2.2         'font-family'
5.2.3         'font-style'
5.2.4         'font-variant'
5.2.5         'font-weight'
5.2.6         'font-size'
5.2.7         'font'
5.3         Color and background properties
5.3.1         'color'
5.3.2         'background'
5.4         Text properties
5.4.1         'word-spacing'
5.4.2         'letter-spacing'
5.4.3         'text-decoration'
5.4.4         'vertical-align'
5.4.5         'text-transform'
5.4.6         'text-align'
5.4.7         'text-indent'
5.4.8         'line-height'
5.5         Box properties
5.5.1         'margin-top', 'margin-right', 'margin-bottom', 'margin-left', 'margin'
5.5.2         'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'padding'
5.5.3         'border-top', 'border-right', 'border-bottom', 'border-left', 'border'
5.5.4         'width'
5.5.5         'height'
5.5.6         'float'
5.5.7         'clear'
5.6         Classification properties
5.6.1         'display'
5.6.2         'list-style'
5.6.3         'white-space'
6         Units
6.1         Length units
6.2         Percentage units
6.3         Color units
6.4         URL
7         CSS1 conformance
7.1         forward-compatible grammar
7.2         Parsing conventions
8         References
9         Acknowledgments

Appendix A: Sample style sheet for HTML 2.0
Appendix B: A sample lex/yacc grammar
Appendix C: Encoding
Appendix D: The applicability and extensibility of CSS1


the author of an HTML document
block-level element
an element which has a line break before and after (e.g. 'H1' in HTML)
the part of the UA's drawing surface onto which documents are rendered
contextual selector
a selector that matches elements based on their position in the document structure. A contextual selector consists of several simple selectors. E.g., the contextual selector 'H1.initial B' consists of two simple selectors, 'H1.initial' and 'B'.
Cascading Style Sheets
Cascading Style Sheets, level 1. This document defines CSS1 which is a simple style sheet mechanism for the web.
a property (e.g. 'font-size') and a corresponding value (e.g. '12pt')
the designer of a style sheet
HTML document
HTML element
fictional tag sequence
a tool for describing the behavior of pseudo-classes and pseudo-elements
Hypertext Markup Language [2], an application of SGML.
HTML extension
Markup introduced by UA vendors, most often to support certain visual styles. The "FONT", "CENTER" and "BLINK" elements are examples of HTML extensions, as are the "BGCOLOR" attribute. One of the goals of CSS is to provide an alternative to HTML extensions.
inline element
an element which does not have a line break before and after (e.g. 'STRONG' in HTML)
intrinsic dimension
a dimension (width, height) defined by the element itself, not imposed by the surroundings. E.g., images come with their own intrinsic dimension.
pseudo-elements are used in CSS selectors to address typographical items (e.g. the first line of an element) rather than structural elements.
pseudo-classes are used in CSS selectors to allow information external to the HTML source (e.g. the fact that an anchor has been visited or not) to classify elements.
a stylistic parameter that can be influenced through CSS. This specification defines a list of properties and their corresponding values.
the person for whom the document is rendered
replaced element
an element that the CSS formatter only knows the width and height of. In HTML, 'IMG', 'INPUT', 'TEXTAREA', 'SELECT' and 'OBJECT' elements can be examples of replaced elements. E.g., the content of the IMG element is often replaced by the image that the SRC attribute points to.
a declaration (e.g. 'font-family: helvetica') and its selector (e.g. 'H1')
a string that identifies what elements the corresponding rule applies to. A selector can either be a simple selector (e.g. 'H1') or a contextual selector (e.g. 'H1 B') which consists of several simple selectors.
Standard Generalized Markup Language [3], of which HTML is an application
simple selector
a selector that matches elements based on their type or attributes, e.g 'H1.initial'
style sheet
a collection of rules
HTML tag, e.g. 'H1'.
User Agent, often a "web browser" or "web client"
synonymous with "reader"
the priority of a declaration
In the text of this specification, single quotes ('...') denote HTML and CSS excerpts.

1    Basic concepts

Designing simple style sheets is easy. One only needs to know a little HTML and some basic desktop publishing terminology. E.g., to set the text color of 'H1' elements to blue, one can say:

  H1 { color: blue }

The example above is a simple CSS rule. A rule 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 one of the properties needed for rendering an HTML document, it qualifies as a style sheet on its own. Combined with other style sheets (one fundamental feature of CSS is that style sheets are combined) it will determine the final presentation of the document.

The selector is the link between the HTML document and the style, and all HTML tags are possible selectors. HTML tags are defined in the HTML specification [2], and the CSS1 specification defines a syntax for how to address them.

The 'color' property is one of around 35 properties that determine the presentation of an HTML document. The list of properties and their possible values is defined in this specification.

HTML authors only need to write style sheets if they want to suggest a specific style for their documents. Each User Agent (UA, often a "web browser" or "web client") will have a default style sheet that presents documents in a reasonable -- but arguably mundane -- manner. Appendix A contains a sample style sheet to present HTML documents as suggested in the HTML 2.0 specification.

1.1    Containment in HTML

In order for the style sheets to influence the presentation, the UA must be aware of their existence. Another W3C working draft, HTML3 and Style Sheets [4], describes how to link HTML with style sheets:

      HREF="http://style.com/cool" TITLE="Cool">
    <STYLE TYPE="text/css">
      @import url(http://style.com/basic);
      H1 { color: blue }
    <H1>Headline is blue</H1>
    <P STYLE="color: green">While the paragraph is green.

The example shows four ways to combine style and HTML: using the 'LINK' element to link an external style sheet, a 'STYLE' element inside the 'HEAD' element, an imported style sheet using the CSS '@import ...' notation, and a 'STYLE' attribute on an element inside 'BODY'. The latter option mixes style with content and one loses the corresponding advantages of traditional style sheets.

The 'LINK' element references alternative style sheets that the reader can select, while imported style sheets are automatically merged with the rest of the style sheet.

Traditionally, UAs have silently ignored unknown tags. As as result, old UAs will ignore the 'STYLE' element, but its content will be treated as part of the document body, and rendered as such. During a transition phase, 'STYLE' element content may be hidden using SGML comments:

  <STYLE TYPE="text/css"><!--
    H1 { color: green }

Since the 'STYLE' element is declared as "CDATA" in the DTD (as defined in [4]), conformant SGML parsers will not consider the above style sheet to be a comment that is to be removed.

1.2    Grouping

To reduce the size of style sheets, one can group selectors in comma-separated lists:

  H1, H2, H3 { font-family: helvetica }

Similarly, declarations can be grouped:

  H1 { 
    font-weight: bold; 
    font-size: 12pt;
    line-height: 14pt; 
    font-family: helvetica; 
    font-style: normal

In addition, some properties have their own grouping syntax:

  H1 { font: 12pt/14pt helvetica }

The above example sets the 'font-size', 'line-height' and 'font-family' properties.

1.3    Inheritance

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>

If no color has been assigned to 'EM', the emphasized "is" will inherit the color of the parent element, i.e. it will also appear in blue. Other style properties are likewise inherited, e.g. 'font-family' and 'font-size'.

Inheritance starts at the oldest ancestor, i.e. the top-level element. In HTML, this is the 'HTML' element which is followed by the 'BODY' element. In order to set a "default" style property, one can use 'BODY' as selector:

  BODY { 
    color: black;
    background: url(texture.gif) white;

This will work even if the author has omitted the 'BODY' tag (which is legal) since the parser will infer the missing tag. The example above sets the text color to be black and the background to be an image. The background will be white if the image is not available. (See the description of the 'background' property for more on this.)

Some style properties are not inherited from the parent element to the child element. Most often it is intuitive why this is not the case. E.g., the 'background' property does not inherit, but the parent element's background will shine through by default.

Often, the value of a property is a percentage that refers to another property:

  P { font-size: 10pt }
  P { line-height: 120% }  /* relative to 'font-size', i.e. 12pt */

For each property that allows percentage values, it is defined what property it refers to. Children elements of 'P' will inherit the computed value of 'line-height' (i.e. 12pt), not the percentage.

1.4    Class as selector

To increase the granularity of control over elements, HTML3 [4][5] proposes a new attribute: 'CLASS'. All elements inside the 'BODY' element can be classed, and the class can be addressed in the style sheet:

  <STYLE TYPE="text/css">
    H1.punk { color: #00FF00 }
  <H1 CLASS=punk>Way too green</H1>

The normal inheritance rules apply to classed elements; they inherit values from their parent in the document structure.

One can address all elements of the same class by omitting the tag name in the selector:

  .punk { color: green }  /* all elements with CLASS punk */

Only one class can be specified per selector. 'P.punk.rap' is therefore an invalid selector in CSS1. (Contextual selectors, described below, can have one class per simple selector)

CSS gives so much power to the CLASS attribute, that in many case it doesn't even matter what HTML element the class is set on -- you can make any element emulate almost any other. Relying on this power is not recommended, since it removes the level of structure that has a universal meaning (HTML elements). A structure based on CLASS is only useful within a restricted domain, where the meaning of a class has been mutually agreed upon.

1.5    ID as selector

HTML3 also introduces the 'ID' attribute which is guaranteed to have a unique value over the document. It can therefore be of special importance as a style sheet selector, and can be addressed with a preceding '#':

  #z098y { letter-spacing: 0.3em }

  <P ID=z098y>Wide text</P>

By using the ID attribute as selector, one can set style properties on a per-element basis. While style sheets have been designed to augment document structure, this feature will allow authors to create documents that present well on the canvas without taking advantage of the structural elements of HTML. This use of style sheets is discouraged.

1.6    Contextual selectors

Inheritance saves CSS designers typing. Instead of setting all style properties, one can create defaults and then list the exceptions. To give 'EM' elements within 'H1' a different color, one may specify:

  H1 { color: blue }
  EM { color: red }

When this style sheet is in effect, all emphasized sections, within or outside 'H1' will turn red. Probably, one only wanted 'EM' elements within 'H1' to turn red and this can be specified with:

  H1 EM { color: red }

The selector is now a search pattern on the stack of open elements, and this type of selector is referred to as a "contextual selector". Contextual selectors consist of several simple selectors separated by white space (all selectors described up to now have been simple selectors). Only elements that match the last simple selector (in this case the 'EM' element) are addressed, and only so if the search pattern matches. Contextual selectors in CSS1 look for ancestor relationships, but other relationships (e.g. parent-child) may be introduced in later revisions. In the example above, the search pattern matches if 'EM' is a descendant of 'H1', i.e. if 'EM' is inside an 'H1' element.

  UL LI    { font-size: small }    
  UL UL LI { font-size: x-small }

Here, the first selector matches 'LI' elements with at least one 'UL' ancestor. The second selector matches a subset of the first, i.e. 'LI' elements with at least two 'UL' ancestors. The conflict is resolved by the second selector being more specific due to the longer search pattern. See the cascading order (section 3.2) for more on this.

Contextual selectors can look for tags, classes, IDs or combinations of these:

  DIV P           { font: small sans-serif }
  .reddish H1     { color: red }
  #x78y CODE      { background: blue }
  DIV.sidenote H1 { font-size: large }

The first selector matches all 'P' elements that has a 'DIV' among the ancestors. The second selector matches matches all 'H1' elements that have an ancestor of class 'reddish'. The third selector matches all 'CODE' elements that are descendants of the element with 'ID=x78y'. The fourth selector matches all 'H1' elements that have a 'DIV' ancestor with class 'sidenote'.

Several contextual selectors can be grouped together:

  H1 B, H2 B, H1 EM, H2 EM { color: red }
Which is equivalent to:
  H1 B { color: red }
  H2 B { color: red }
  H1 EM { color: red }
  H2 EM { color: red }


Textual comments in CSS style sheets are similar to those in the C programming language:

  EM { color: red }  /* red, really red!! */

Comments cannot be nested.

2    Pseudo-classes and pseudo-elements

In CSS1, style is normally attached to an element based on its position in the document structure. This simple model is sufficient for a wide variety of styles, but doesn't cover some common effects. The concept of pseudo-classes and pseudo-elements extend addressing in CSS1 to allow external information to influence the formatting process.

Pseudo-classes and pseudo-elements can be used in CSS selectors, but do not exist in the HTML source. Rather, they are "inserted" by the UA under certain conditions to be used for addressing in style sheets. They are referred to as "classes" and "elements" since this is a convenient way of describing their behavior. More specifically, their behavior is defined by a "fictional tag sequence" where they have a well-defined order.

Pseudo-elements are used to address sub-parts of elements, while pseudo-classes allow style sheets to differentiate between different element types.

2.1    Anchor pseudo-classes

User agents commonly display newly visited anchors differently from older ones. In CSS1, this is handled through pseudo-classes on the 'A' element:

  A:link { color: red }       /* unvisited link */
  A:visited { color: blue }   /* visited links */
  A:active { color: lime }    /* active links */

All 'A' elements with an 'HREF' attribute will be put into one of these groups (i.e. target anchors are not affected). UAs may choose to move an element from 'visited' to 'link' after a certain time. An 'active' link is one that is currently being selected (e.g. by a mouse button press) by the reader. A UA is not required to reformat a currently displayed document due to anchor pseudo-class transitions. E.g., a style sheet can legally specify that the 'font-size' of an 'active' link should be larger that a 'visited' link, but the UA is not required to dynamically reformat the document when the reader selects the 'visited' link.

The formatting of an anchor pseudo-class is as if the class had been inserted manually. Ancher pseudo-classes have no effect on elements other than 'A'.

Pseudo-classes can be used in contextual selectors:

  A:link IMG { border: solid blue }

Also, pseudo-classes can be combined with normal classes:

  A.external:visited { color: blue }

  <A CLASS=external HREF="http://out.side/">external link</A>

If the link in the above example has been visited, it will be rendered in blue. Note that normal class names precede pseudo-classes in the selector.

2.2    Typographical pseudo-elements

Some common typographic effects are associated not with structural elements but rather typographical items as formatted on the canvas. In CSS1, two such typographical items can be addressed through pseudo-elements: the first line of an element, and the first letter.

2.3    The 'first-line' pseudo-element

The 'first-line' pseudo-element is used to apply special styles to the first line as formatted on the canvas:

  <STYLE TYPE="text/css">
    P:first-line { font-style: small-caps }

  <P>The first line of an article in Newsweek.

On an text-based UA, this could be formatted as:

  article in Newsweek.

The fictional tag sequence in the above example is: "<P> <P:first-line> The first line of an </P:first-line> article in Newsweek.</P>". The 'first-line' end tag is inserted at the end of the first line as formatted on the canvas.

The 'first-line' pseudo-element can only be attached to a block-level element.

2.4    The 'first-letter' pseudo-element

The 'first-letter' pseudo-element is used for "initial caps" and "drop caps" which are common typographic effects. All normal properties 'first-letter' elements and the formatting should be accordingly. This is how you could make a dropcap initial letter span two lines:

  <STYLE TYPE="text/css">
   P              { font-size: 12pt; line-height: 12pt }
   P:first-letter { font-size: 200%; float: left }
   SPAN           { text-transform: uppercase }
  <P><SPAN>The first</SPAN> few words of an article in The Economist.</P>

(The 'SPAN' element is being proposed as a new character-level element for HTML3)

If an text-based UA supports the 'first-letter' pseudo-element (we do not expect them to), the above could be formatted as:

   | HE FIRST few words
   |of an article in the

The fictional tag sequence is: "<P> <SPAN> <P:first-letter> T </P:first-letter> he first </SPAN> few words of an article in the Economist. </P>". Note that the 'first-letter' pseudo-element tags abut the content (i.e. the initial character), while the 'first-line' pseudo-element start tag is inserted right after the start tag of the element they are attached to.

The UA defines what characters are inside the 'first-letter' element. Normally, quotes that precede the first letter should be included:

  || /\ is the first
    /  \ letter of the
   /----\ alphabet,"
  /      \  said the
  wizard to the child.

When the paragraph starts with other punctuation (e.g. parenthesis and ellipsis points) or other characters that are normally not considered letters (e.g. digits and mathematical symbols), 'first-letter' pseudo-elements are usually ignored.

Some languages may have specific rules about how to treat certain letter combinations. In Dutch, for example, if the letter combination "ij" appears in the beginning of a word, they should both be considered within the 'first-letter' pseudo-element.

The 'first-letter' pseudo-element can only be attached to a block-level element.

2.5    Pseudo-elements in selectors

In a contextual selector, pseudo-elements are only allowed in the last simple selector:

  BODY P:first-letter { color: purple }

Pseudo-elements can be combined with classes in selectors:

  P.initial:first-letter { color: red }

  <P CLASS=initial>First paragraph</A>

The above example would make the first letter of all 'P' elements with 'CLASS=initial' red. When combined with classes or pseudo-classes, pseudo-elements should be specified at the end of the selector. Only one pseudo-element can be specified per selector.

2.6    Multiple pseudo-elements

Several pseudo elements can be combined:

  P { color: red; font-size: 12pt }
  P:first-letter { color: green; font-size: 200% }
  P:first-line { color: blue }

In this example, the first letter of each 'P' element would be green with a font size of 24pt. The rest of the first line (as formatted on the canvas) would be blue while the rest of the paragraph would be red. The fictional tag sequence is: "<P> <P:first-line> <P:first-letter> ... </P:first-letter> ... <P:/first-line> </P>".

Note that the 'first-letter' element is inside the 'first-line' element. Properties set on 'first-line' will be inherited by 'first-letter', but are overridden if the same property is set on 'first-letter'.

Possibly, pseudo-elements influencing the same content can be set on different elements:

  BODY:first-letter { color: red }
  P:first-letter { font-size: 200% }

  <BODY><P>some text ...

The fictional tag sequence of the above example is "<BODY> <BODY:first-letter> <P> <P:first-letter> some text ..."

If a pseudo-element breaks up a real element the necessary extra tags must be regenerated in the fictional tag sequence. For example, if a SPAN element spans over a </P:first-line> tag, a set of SPAN end and start tags must be regenerated and the fictional tag sequence becomes "<P><P:first-line><SPAN>This text is inside a long</SPAN></P:first-line><SPAN>span element</SPAN>".

3    The cascade

In CSS, more than one style sheet can influence the presentation simultaneously. There are two main reasons for this feature: modularity and author/reader balance.

A style sheet designer can combine several (partial) style sheets to reduce redundancy:
  @import url(http://www.style.org/punk);
  @import url(http://www.style.org/funk);

  H1 { color: red }     /* override imported sheets */
author/reader balance
Both readers and authors can influence the presentation through style sheets. To do so, they use the same style sheet language thus reflecting a fundamental feature of the web: everyone can become a publisher. The UA is free to choose the mechanism for referencing personal style sheets.

Sometimes conflicts will arise between the style sheets that influence the presentation. Conflict resolution is based on each style rule having a weight. By default, the weights of the reader's rules are less than the weights of rules in the author's documents. I.e., if there are conflicts between the style sheets of an incoming document and the reader's personal sheets, the author's rules will be used. Both reader and author rules override UA's default values.

3.1    'important'

Style sheet designers can increase the weights of their rules:

  H1 { color: red ! important }
  P  { font-size: 12pt ! important }

An important reader rule will override an author rule with normal weight. An important author rule will override an important reader rule.

3.2    Cascading order

Conflicting rules are intrinsic to the CSS mechanism. To find the value for an element/property combination, the following algorithm should be followed:

  1. Find all declarations that apply to the element/property in question. Declarations apply if the selector matches the element in question. If no declarations apply, the inherited value is used. If there is no inherited value (this is the case on the root element and for properties that do not inherit), the initial value is used.
  2. Sort the declarations by explicit weight: declarations marked '!important' carry more weight than unmarked (normal) declarations.
  3. Sort by origin: the author's style sheets override the reader's style sheet which override the UA's default values.
  4. Sort by specificity of selector: more specific selectors will override more general ones. To find the specificity, count the number of ID attributes in the selector (a), the number of CLASS attributes in the selector (b), and the number of tag names in the selector (c). Concatenating the three numbers (in a number system with a large base) gives the specificity. Some examples:
      LI            {...}  /* a=0 b=0 c=1 -> specificity =   1 */
      UL LI         {...}  /* a=0 b=0 c=2 -> specificity =   2 */
      UL OL LI      {...}  /* a=0 b=0 c=3 -> specificity =   3 */
      LI.red        {...}  /* a=0 b=1 c=1 -> specificity =  11 */
      UL OL LI.red  {...}  /* a=0 b=1 c=3 -> specificity =  13 */ 
      #x34y         {...}  /* a=1 b=0 c=0 -> specificity = 100 */ 

    Pseudo-elements and pseudo-classes are counted as normal elements and classes, respectively.

  5. Sort by order specified: if two rules 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 that apply to the same element/property combination.

This strategy gives author's 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 a certain style sheet, e.g. through a pull-down menu.

A declaration in the 'STYLE' attribute of an element (see section 1.1 for an example) has the same weight as a declaration with an ID-based selector that is specified at the end of the style sheet:

<STYLE TYPE="text/css">
  #x97z { color: blue }

<P ID=x97z STYLE="color: red">

In the above example, the color of the 'P' element would be red. Although the specificity is the same for both declarations, the declaration in the 'STYLE' attribute will override the one in the 'STYLE' element due to cascading rule number 5.

The UA may choose to honor other stylistic attributes, for example 'ALIGN'. Such an attribute should be translated to a corresponding CSS rule with specificity equal to 1. The rule is assumed to be at the start of the author style sheet and may be overridden by subsequent rules.

4    Formatting model

This document suggests a simple box-oriented formatting model. Each block-level element (e.g. 'H1' and 'P', but not 'EM') is surrounded by a box. The size of the box is the sum of the element width (i.e. formatted text or image), the padding, the border and the margins:

   |                                       |
   |           margin (transparent)        |
   |   _________________________________   |
   |  |                                 |  |
   |  |        border                   |  |
   |  |   ___________________________   |  |
   |  |  |                           |  |  |
   |  |  |     padding               |  |  |
   |  |  |   _____________________   |  |  |
   |  |  |  |                     |  |  |  |
   |  |  |  |  content            |  |  |  |
   |  |  |  |_____________________|  |  |  |
   |  |  |___________________________|  |  |
   |  |_________________________________|  |

            |    element width    |

   |               box width               |

The size of the margin, border and padding are set with the 'margin', 'border' and 'padding' properties respectively. The padding area uses the same background as the element itself (set with the 'background' property). The color and style for the border is set with the 'border' property. The margins are always transparent, so the parent element will shine through.

The following example shows how margins and padding format a 'UL' element with two children. To simplify the diagram there are no borders.

    <STYLE TYPE="text/css">
      UL { 
        background: red; 
        margin: A B C D;      /* let's pretend we have constants in CSS1 */
        padding: E F G H;     /*                   "                     */
      LI { 
        color: white;    
        background: blue;     /* so text is white on blue */ 
        margin: a b c d;      /* let's pretend we have constants in CSS1 */
        padding: e f g h;     /*                   "                     */
      <LI>1st element of list
      <LI>2nd element of list
  |                                                       |
  |    A      UL margin (transparent)                     |
  |    _______________________________________________    |
  | D |                                               | B |
  |   |    E   UL padding (red)                       |   |
  |   |    _______________________________________    |   |
  |   | H |                                       | F |   |
  |   |   |    a   LI margin (transparent,        |   |   |
  |   |   |        so red shines through)         |   |   |
  |   |   |    _______________________________    |   |   |
  |   |   | d |                               | b |   |   |
  |   |   |   |    e    LI padding (blue)     |   |   |   |
  |   |   |   |                               |   |   |   |
  |   |   |   | h  1st element of list      f |   |   |   |
  |   |   |   |                               |   |   |   |
  |   |   |   |    g                          |   |   |   |
  |   |   |   |_______________________________|   |   |   |
  |   |   |                                       |   |   |
  |   |   |     max(a, c)                         |   |   | <- note the max
  |   |   |                                       |   |   |
  |   |   |    _______________________________    |   |   |
  |   |   |   |                               |   |   |   |
  |   |   | d |    e    LI padding (blue)     |   |   |   |
  |   |   |   |                               |   |   |   |
  |   |   |   | h  2nd element of list      f |   |   |   |
  |   |   |   |                               |   |   |   |
  |   |   |   |    g                          |   |   |   |
  |   |   |   |_______________________________|   |   |   |
  |   |   |                                       |   |   |
  |   |   |   c    LI margin (transparent,        |   |   |
  |   |   |        so red shines through)         |   |   |
  |   |   |_______________________________________|   |   |
  |   |                                               |   |
  |   |    G                                          |   |
  |   |_______________________________________________|   |
  |                                                       |
  |   C                                                   |

Technically, padding and margin properties are not inherited. But, as the example shows, the placement of an element is relative to ancestors and siblings so these elements' padding and margin properties have an effect on their children.

If the border width had been set (the default value is '0'), the border would have appeared between the padding and the margins.

4.1    Vertical formatting

The width of the margins specify the minimum distance to the edges of surrounding boxes. Two or more adjoining margins (i.e., with no border, padding or content between them) are collapsed to use the maximum of the margin values. In the example above, the margins between the two 'LI' elements are collapsed by using the maximum of the first LI element's 'margin-bottom' and the second LI element's 'margin-top'. Similarly, if the padding between the 'UL' and the first 'LI' element (the "E" constant) had been zero, the margins of the UL and first LI elements should have been collapsed.

In the case of negative margins, the absolute maximum of the negative adjoining margins should be deducted from the maximum of the positive adjoining margins.

4.2    Horizontal formatting

Seven properties influence the horizontal dimension of a box: 'margin-left', 'border-left', 'padding-left', 'width', 'padding-right', 'border-right', and 'margin-right'. Added up, these have to be equal to the width of the parent element. Unless they do add up, one of these properties must have a value of 'auto'. Therefore, the formatter may have to assign a value of 'auto' either to 'margin-left' or 'margin-right'. The value of the 'float' property determines which of these are reassigned: if 'float' has a value of 'left' or 'none', 'margin-right' is assigned to 'auto'. If 'float' has a value of 'right', 'margin-left' is assigned to 'auto'. This scheme ensures that images can be positioned on the left or right side with just one declaration:

  IMG.icon { float: right }

Since images come with an intrinsic dimesion, either 'margin-left' or 'margin-right' will have to be assigned to 'auto' in the example above. Since 'float' has a value of 'right', 'margin-left' will be assigned to 'auto' and 'margin-right will remain '0'.

4.3    Lists

Elements with a 'display' property value of 'list-item' are preceded by a label. The type of label is determined by the 'list-style' property. The label is not considered to be a part of the content, and will be placed outside the content. The rendering of the label should be based on the font and color properties of the element it belongs to.

4.4    The canvas

The canvas is the part of the UA's drawing surface onto which documents are rendered. No structural element of a document correspond to the canvas, and this raises two issues when formatting a document:

A reasonable answer to the first question is that the initial size of the canvas is based on the window size, but CSS1 leaves this issue for the UA to decide.

HTML extensions have set a precedence for the second question: attributes on the 'BODY' element set the background of the whole canvas. To support designers' expectations, CSS1 introduces a special rule to find the canvas background:

If the 'background' value of the 'HTML' element is different from 'transparent' then use it, else use the 'background' value of the 'BODY' element. If the resulting value is 'transparent', the rendering is undefined.

This rule allows:

  <HTML STYLE="background: url(http://style.com/marble.png)">
  <BODY STYLE="background: red">

In the example above, the canvas will be covered with "marble". The background of the 'BODY' element (which may or may not fully cover the canvas will be red.

Until other means of addressing the canvas become available, we recommend setting canvas properties on the 'BODY' element.

4.5    Floating elements

Using the 'float' property, elements can be declared to be outside the normal flow of elements. For example, by setting the 'float' property of an image to 'left', the normal flow will wrap around on the right side. The image's position will be taken from the margin properties.

<STYLE TYPE="text/css">
  IMG.icon { 
    float: left;
    margin-left: 2em;

<IMG CLASS=icon SRC=star.gif>
<P>Some text to show how text wraps around floating images

The above example could be formatted as:

     |   |Some text
     | * |to show how
     |___|text wraps 
  around floating images

4.6    Replaced elements

A replaced element is an element which is replaced by content pointed to from the element. E.g., in HTML, the IMG element is replaced by the image pointed to by the SRC attribute. One can assume that replaced elements come with their own intrinsic dimension. If the CSS values for 'width' is 'auto', the intrinsic width should be used as the width of the element. If a value other than 'auto' is specified in the style sheet, this value should be used and the replaced element should be resized accordingly (the resize method will depend on the media type). The 'height' property is used in the same manner.

4.7    The height of lines

All elements other then replaced elements have a 'line-height' property that, in principle, gives the total height of a line of text. Space is added above and below the text of the line to arrive at that line height. For example, if the text is 12pt high and 'line-height' is set to '14pt', an extra space of 2pt is added, namely 1pt above and 1pt below the line.

The difference between the height of the text and the 'line-height' is called the leading. Half the leading is called the half-leading. The height of the text is the overall height of the font, which is often the same as, or very close to, the 'font-size'. After formatting, each line will form a rectangular line-box.

If a line of text contains sections with different 'line-height' values (because there are inline elements on the line), then each of those sections has its own half-leading above and below. The height of the line-box is from the top of the highest section to the bottom of the lowest one. To form a paragraph, the line-boxes are put directly below each other.

On the first line of a box, no half-leading is added above the text. On the last line of a box, no half-leading is added below the text. (Instead, the box's padding is added there, as described in the formatting model.)

Replaced elements (e.g. images) on the line can make the line-box bigger, if the top of the replaced element (including all of its padding, border and margin), is above the tallest text section, or if the bottom is below the lowest.

In the normal case, when there is only one value of 'line-height' throughout a paragraph, and no tall images, the definition above will ensure that baselines of successive lines are exactly 'line-height' apart. This is important when columns of text in different fonts have to be aligned, for example in a table.

Note that this doesn't preclude the text on two adjacent lines from overlapping each other. The 'line-height' may be smaller than the height of the text, in which case the leading will be negative. This is actually quite useful if you know that the text will contain no descenders (because it only contains uppercase, e.g.), so the lines can be put closer together.

4.8    'BR' elements

The current CSS1 properties and values cannot describe the behavior of the 'BR' element. In HTML, the 'BR' element specifies a line break between words. In effect, the element is replaced by a line break. We expect future versions of CSS to handle added and replaced content, but CSS1-based formatters must treat 'BR' specially.

5    CSS1 properties

Style sheets influence the presentation of documents by assigning values to style properties. This section lists the defined style properties, and their corresponding list of possible values, of CSS1.

5.1    Notation for property values

In the text below, the allowed values for each property are listed with a syntax like the following:

Value: N | NW | NE
Value: [ <length> | thick | thin ]{1,4}
Value: <url>? <color> [ / <color> ]?
Value: <url> || <color>

The words between "<" and ">" give a type of value. The most common types are <length>, <percentage>, <url>, <number> and <color>; these are described in the section on units. The more specialized types (e.g. <font-family> and <border-style>) are described under the property where they appear.

Other words are keywords that must appear literally, without quotes. The slash (/) is also considered a keyword.

Several things juxtaposed mean that all of them must occur, in the given order. A bar (|) separates alternatives: one of them must occur. A double bar (A || B) means that either A or B or both must occur, in any order. Brackets ([]) are for grouping. Juxtaposition is stronger than the double bar, and the double bar is stronger than the bar. Thus "a b | c || d e" is equivalent to "[ a b ] | [ c || [ d e ]]".

Every type, keyword, or bracketed group may be followed by one of the following modifiers:

5.2    Font properties

Setting font properties will be among the most common uses of style sheets. Unfortunately, there exists no well-defined and universally accepted taxonomy for classifying fonts, and terms that apply to one font family may not be appropriate for others. E.g. 'italic' is commonly used to label slanted text, but slanted text may also be labeled as being Oblique, Slanted, Incline, Cursive or Kursiv. Therefore it is not a simple problem to map typical font selection properties to a specific font.

CSS1 defines the properties 'font-family', 'font-size', 'font-weight', 'font-style' and 'font-variant'. Additional font characteristics are being worked on in the W3C Fonts working group. These will complement the properties defined in CSS1.

5.2.1    Font matching

Because there is no accepted, universal taxonomy of font properties, matching of properties to font faces must be done carefully. The properties should be matched in a well-defined order to insure that the results of this matching process are as consistent as possible across UAs (assuming that the same library of font faces is presented to each of them).

  1. The User Agent makes a database of relevant CSS1 properties of all the fonts of which the UA is aware. The UA may be aware of a font because it has been installed locally or it has been previously downloaded over the Web. If there are two fonts with exactly the same properties, one of them is ignored.
  2. At a given element and for each character in that element, the UA assembles the font-properties applicable to that element. Using the complete set of properties, the UA uses the 'font-family' property to choose a tentative font family. The remaining properties are tested against the family according to the matching criteria described with each property. If there are matches for all the remaining properties, then that is the matching font face for the given element.
  3. If there is no matching font face within the 'font-family' being processed by step 2, and if there is a next alternative 'font-family' in the font set, then repeat step 2 with the next alternative 'font-family'.
  4. If there is a matching font face, but it doesn't contain a glyph for the current character, and if there is a next alternative 'font-family' in the font sets, then repeat step 2 with the next alternative 'font-family'. See appendix C for a description of font and character encoding.
  5. If there is no font within the family selected in 2, then use a UA-dependent default 'font-family' and repeat step 2, using the best match that can be obtained within the default font.

(The above algorithm can be optimized to avoid having to revisit the CSS1 properties for each character.)

The per-property matching rules from (2) above are as follows:

  1. 'font-style' is tried first. 'italic' will be satisfied if there is either a face in the UA's font database labeled with the CSS keyword 'italic' (preferred) or 'oblique'. Otherwise the values must be matched exactly or font-style will fail.
  2. 'font-variant' is tried next. 'normal' can only match a font labeled with font-variant 'normal'. 'small-caps' can be satisfied by: 1) a small-caps font, 2) a synthesized small-caps font, 3) using uppercase letters as replacements for lowercase letters. A small-caps font can be synthesized by electronically reducing and widening the uppercase letters from a normal font.
  3. 'font-weight' is matched next, it will never fail. (See 'font-weight' below.)
  4. 'font-size' must be matched within a UA-dependent margin of tolerance. (Typically, sizes for scalable fonts are rounded to the nearest whole pixel, while the tolerance for bitmapped fonts could be as large as 20%.) Further computations, e.g. by 'em' values on other properties, are based on the 'font-size' value that is used, not the one that is specified.

5.2.2    'font-family'

Value: [[<family-name> | <generic-family>],]* [<family-name> | <generic-family>]
Initial: UA specific
Applies to: all elements
Inherited: yes
Percentage values: N/A

The value is a prioritized list of font family names and/or generic family names. Unlike most other CSS1 properties, values are separated by a comma to indicate that they are alternatives:

  BODY { font-family: gill, helvetica, sans-serif }
There are two types of list values:
The name of a font family of choice. In the last example, "gill" and "helvetica" are font families.
In the example above, the last value is a generic family name. The following generic families are defined: Style sheet designers are encouraged to offer a generic font family as a last alternative.
Font names containing white space should be quoted:
  BODY { font-family: "new century schoolbook", serif }
  <BODY STYLE="font-family: 'My own font', fantasy">

If quoting is omitted, any white space characters before and after the font name is ignored and any sequence of white space characters inside the font name is converted to a single space.

5.2.3    'font-style'

Value: normal | italic | oblique
Initial: normal
Applies to: all elements
Inherited: yes
Percentage values: N/A

The 'font-style' property selects between normal (sometimes referred to as "roman" or "upright"), italic and oblique faces within a font family.

A value of 'normal' selects a font that is classified as 'normal' in the UA's font database, while 'oblique' selects a font that is labeled 'oblique'. A value of 'italic' selects a font that is labeled 'italic', or, if that is not available, one labeled 'oblique'.

The font that is labeled 'oblique' in the UA's font database may actually have been generated by electronically slanting a normal font.

Fonts with Oblique, Slanted or Incline in their names will typically be labeled 'oblique' in the UA's font database. Fonts with Italic, Cursive or Kursiv in their names will typically be labeled 'italic'.

  H1, H2, H3 { font-style: italic }
  H1 EM { font-style: normal }

In the example above, emphasized text within 'H1' will appear in a normal face.

5.2.4    'font-variant'

Value: normal | small-caps
Initial: normal
Applies to: all elements
Inherited: yes
Percentage values: N/A

Another type of variation within a font family is the small-caps. In a small-caps font the lower case letters look similar to the uppercase ones, but in a smaller size and with slightly different proportions. The 'font-variant' property selects that font.

A value of 'normal' selects a font that is not a small-caps font, 'small-caps' selects a small-caps font. It is acceptable in CSS1 if the small-caps font is a created by taking a normal font and replacing the lower case letters by electronically reduced and widened uppercase characters. As a last resort, uppercase letters will be used as replacement for a small-caps font.

The following example results in an 'H3' element in small-caps, with emphasized words in oblique small-caps:

  H3 { font-variant: small-caps }
  EM { font-style: oblique }

There may be other variants in the font family as well, such as fonts with old-style numerals, small-caps numerals, condensed or expanded letters, etc. CSS1 has no properties that select those.

5.2.5    'font-weight'

Value: normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
Initial: normal
Applies to: all elements
Inherited: yes
Percentage values: N/A

The 'font-weight' property selects the weight of the font. The values '100' to '900' form an ordered sequence, where each number indicates a weight that is at least as dark as its predecessor. The keyword 'normal' is synonymous with '400', and 'bold' is synonymous with '700'.

  P { font-weight: normal }   /* 400 */
  H1 { font-weight: 700 }     /* bold */

The 'bolder' and 'lighter' values select font weights that are relative to the weight inherited from the parent:

  STRONG { font-weight: bolder }

Child elements inherit the resultant weight, not the keyword value.

Fonts (the font data) typically have one or more properties whose values are names that are descriptive of the "weight" of a font. There is no accepted, universal meaning to these weight names. Their primary role is to distinguish faces of differing darkness within a single font family. Usage across font families is quite variant; for example a font that you might think of as being bold might be described as being Regular, Roman, Book, Medium, Semi- or DemiBold, Bold, or Black, depending on how black the "normal" face of the font is within the design. Because there is no standard usage of names, the weight property values in CSS1 are given on a numerical scale in which the value '400' (or 'normal') corresponds to the "normal" text face for that family. The weight name associated with that face will typically be Book, Regular, Roman, Normal or sometimes Medium.

The association of other weights within a family to the numerical weight values is intended only to preserve the ordering of darkness within that family. However, the following heuristics tell how the assignment is done in typical cases:

The following two examples illustrate the process. Assume four weights in the "Example1" family, from lightest to darkest: Regular, Medium, Bold, Heavy. And assume six weights in the "Example2" family: Book, Medium, Bold, Heavy, Black, ExtraBlack. Note how in the second example it has been decided not to assign "Example2 ExtraBlack" to anything.

    Available faces       |  Assignments  |  Filling the holes
    "Example1 Regular"    |  400          |  100, 200, 300
    "Example1 Medium"     |  500          |
    "Example1 Bold"       |  700          |  600
    "Example1 Heavy"      |  800          |  900
    Available faces       |  Assignments  |  Filling the holes
    "Example2 Book"       |  400          |  100, 200, 300
    "Example2 Medium"     |  500          |
    "Example2 Bold"       |  700          |  600      
    "Example2 Heavy"      |  800          |
    "Example2 Black"      |  900          |
    "Example2 ExtraBlack" |  (none)       |

Since the intent of the relative keywords 'bolder' and 'lighter' is to darken or lighten the face within the family and because a family may not have faces aligned with all the symbolic weight values, the matching of 'bolder' is to the next darker face available on the client within the family and the matching of 'lighter' is to the next lighter face within the family. To be precise, the meaning of the relative keywords 'bolder' and 'lighter' is as follows:

There is no guarantee that there will be a darker face for each of the 'font-weight' values; for example, some fonts may only have a normal and a bold face, others may have eight different face weights. There is no guarantee on how a UA will map font faces within a family to weight values. The only guarantee is that a face of a given value will be no less dark than the faces of lighter values.

5.2.6    'font-size'

Value: <absolute-size> | <relative-size> | <length> | <percentage>
Initial: medium
Applies to: all elements
Inherited: yes
Percentage values: relative to parent element's font size

An <absolute-size> keyword is an index to a table of font sizes computed and kept by the UA. Legal values are: [ xx-small | x-small | small | medium | large | x-large | xx-large ]. On a computer screen a scaling factor of 1.5 is suggested between adjacent indexes; if the 'medium' font is 10pt, the 'large' font could be 15pt. Different media may need different scaling factors. Also, the UA should take the quality and availability of fonts into account when computing the table. The table may be different from one font family to another.
A <relative-size> keyword is interpreted relative to the table of font sizes and the font size of the parent element. Legal values are: [ larger | smaller ]. For example, if the parent element has a font size of 'medium', a value of 'larger' will make the font size of the current element be 'large'. If the parent element's size is not close to a table entry, the UA is free to interpolate between table entries or round off to the closest one. The UA may have to extrapolate table values if the numerical value goes beyond the keywords.

Length and percentage values should not take the font size table into account when calculating the font size of the element.

On all other properties, 'em' and 'ex' length values refer to the font size of the current element. On the 'font-size' property, these length units refer 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.


  P { font-size: 12pt; }
  BLOCKQUOTE { font-size: larger }
  EM { font-size: 150% }
  EM { font-size: 1.5em }

If the suggested scaling factor of 1.5 is used, the latter three rules are identical.

5.2.7    'font'

Value: <font-size> [ / <line-height> ]? <font-family>
Initial: not defined
Applies to: all elements
Inherited: yes
Percentage values: allowed on <font-size> and <line-height>

This syntax of this property is based on a traditional typographic shorthand notation to set multiple properties related to fonts: 'font-size', 'line-height' and 'font-family'. For a definition of allowed and initial values, see the previously defined properties. Setting the 'font' property is equivalent to including separate declarations at the same point in the style sheet. If 'line-height' is left out of a 'font' specification, it is set to its initial value.

  P { font: 12pt/14pt sans-serif }
  P { font: 80% sans-serif }
  P { font: x-large/110% "new century schoolbook", serif }

In the second rule, the font size percentage value ('80%') refers to the font size of the parent element. In the last rule, the line height percentage refers to the font size of the element itself.

5.3    Color and background properties

5.3.1    'color'

Value: <color>
Initial: UA specific
Applies to: all elements
Inherited: yes
Percentage values: N/A

This property describes the text color of an element, i.e. the "foreground" color. There are different ways to specify red:

  EM { color: red }              /* natural language */
  EM { color: rgb(255,0,0) }     /* RGB rage 0-255   */

See section 6.3 for a complete description of possible color values.

5.3.2    'background'

Value: transparent | <color> || <url> || <repeat> || <scroll> || <position>
Initial: transparent
Applies to: all elements
Inherited: no
Percentage values: refer to the dimension of the element itself

This property describes the background of an element, i.e. the surface onto which the content (e.g. text) is rendered. Values on this property can be one of:

Corresponding examples:
  P { background: transparent }                              /* transparent */
  BODY { background: red }                                   /* one color */
  BODY { background: url(chess.png) gray 50% repeat fixed }  /* img + controls */

This property does not inherit, but the parent element's background will shine through by default due to the initial transparent value. If neither an image or a color is found, a value of 'transparent' is assumed.

If an image is found through the URL, it will be overlaid on top of any color specified. The color is used:

If no color is specified, the areas not covered by any image will be transparent.

If a background image has been specified, the value of <repeat> determines how/if the image is repeated. Possible values are: [repeat | repeat-x | repeat-y | no-repeat]. If no value is set, 'repeat' is assumed, i.e. the image is repeated both horizontally and vertically.
  BODY { background: url(marble.png) repeat-x }

In the example above, the image will only be repeated horizontally. Similarly, a value of 'repeat-y' will repeat the image vertically.

If a background image has been specified, the value of <scroll> determines if it should be fixed with regard to the canvas or if it should scroll along with the content. Respectively, the possible values are: [fixed | scroll]. If no value is specified, 'scroll' is assumed.
If a background image has been specified, the value of <position> specifies its initial position. Possible values are: [[<percentage> | <length> [<percentage> | <length> ]?] | [top | center | bottom] || [left | center | right] ]. If no value is specified, '0% 0%' is assumed.

With a value pair of '0% 0%', the upper left corner of the image is placed in the upper left corner of the box that surrounds the content of the element (i.e., not the box that surrounds the padding, border or margin). A value pair of '100% 100%' places the lower right corner of the image in the lower right corner of the element. With a value pair of '14% 84%', the point 14% across and 84% down the image is to be placed at the point 14% across and 84% down the element.

With a value pair of '2cm 2cm', the upper left corner of the image is placed 2cm to the right and 2cm below the upper left corner of the element.

If only one percentage or length value is given, it sets both the horizontal and vertical offset of the background image. If two values are given, the horizontal position comes first. Combinations of length and percentage values are allowed, e.g. '50% 2cm'. Negative positions are allowed.

One can also use keyword values to indicate the position of the background image. Keywords can not be combined with percentage values, but the effect is the same. The mapping from keywords to percentages are:

  top    =   0%
  center =  50% 
  bottom = 100%
  left   =   0%
  right  = 100%

The horizontal keywords ('left', 'center', 'right') and the vertical keywords ('top', 'center', 'bottom') may come in any order. If only axis is unspecified, 'center' should be assumed for the other one. Consider the following examples:

  BODY { background: url(banner.jpeg) right top }    /* 100%   0% */
  BODY { background: url(banner.jpeg) top center }   /*  50%   0% */
  BODY { background: url(banner.jpeg) center }       /*  50%  50% */
  BODY { background: url(banner.jpeg) bottom }       /*  50% 100% */

In the first rule of the example aboe, the keywords ('right' 'top') can simply be replaced by percentage values ('100%' '0%'). In the second rule, the percentage values must be reversed since the vertical axis ('top') is specified first. In the third rule, it's ambiguous if 'center' indicates a horizontal or vertical position, but that is irrelevant since unspecified values are assumed to be 'center'. In the fourth rule, the vertical axis is specified and the horizontal is assumed to be 'center'.

If the background image is fixed with regard to the canvas (see the <scroll> value above), the image is placed relative to the canvas instead of the element. E.g.:

  BODY { 
    background: url(logo.png) fixed 100% 100%;

In the example above, the image is placed in the lower right corner of the canvas.

5.4    Text properties

5.4.1    'word-spacing'

Value: normal | <length>
Initial: normal
Applies to: all elements
Inherited: yes
Percentage values: N/A

The length unit indicates an addition to the default space between words. Values can be negative, but there may be implementation-specific limits. The UA is free to select the exact spacing algorithm. The word spacing may also be influenced by justification (which is a value of the 'align' property).

  H1 { word-spacing: 0.4em }

Here, the word-spacing between each word in 'H1' elements would be increased with '1em'.

5.4.2    'letter-spacing'

Value: normal | <length>
Initial: normal
Applies to: all elements
Inherited: yes
Percentage values: N/A

The length unit indicates an addition to the default space between characters. Values can be negative, but there may be implementation-specific limits. The UA is free to select the exact spacing algorithm. The letter spacing may also be influenced by justification (which is a value of the 'align' property).

  BLOCKQUOTE { letter-spacing: 0.1em }

Here, the word-spacing between each character in 'BLOCKQUOTE' elements would be increased with '0.1em'.

With a value of 'normal', the UAs may change the space between letters to justify text. This will not happen if 'letter-spacing' is explicitly set to zero:

  BLOCKQUOTE { letter-spacing: 0 }
  BLOCKQUOTE { letter-spacing: 0cm }

When the resultant space between two letters is not the same as the default space, UAs should not use ligatures.

5.4.3    'text-decoration'

Value: none | [ underline | overline | line-through | blink ]+
Initial: none
Applies to: all elements
Inherited: no, but see clarification below
Percentage values: N/A

This property describes decorations that are added to the text of an element. If the element has no text (e.g. the IMG element in HTML) or is an empty element (e.g. "<EM></EM>"), this property has no effect.

The color(s) required for the text decoration should be derived from the 'color' property value.

This property is not inherited, but elements should match their parent. E.g., if an element is underlined, the line should span the child elements. The color of the underlining will remain the same even if descendant elements have different 'color' values.

  A:link, A:visited, A:active { text-decoration: underline }

The example above would underline the text of all active links.

We expect UA vendors to propose several new values on this property. Formatters should treat unknown values as 'underline'.

5.4.4    'vertical-align'

Value: baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage>
Initial: baseline
Applies to: inline and replaced elements
Inherited: no
Percentage values: refer to the 'line-height' of the element itself

The property affects the vertical positioning of the element. One set of keywords is relative to the parent element:

align the baseline of the element with the baseline of the parent
align the vertical midpoint of the element (typically an image) with the baseline plus half the x-height of the parent
subscript the element
superscript the element
align the top of the element with the top of the parent element's font
align the bottom of the element with the bottom of the parent element's font
Another set of properties are relative to the formatted line that the element is a part of:
align the top of the element with the tallest element on the line
align the bottom of the element with the lowest element on the line

Using the 'top' and 'bottom' alignment, unsolvable situations can occur where element dependencies form a loop.

Percentage values refer to the 'line-height' of the element itself. E.g., a value of '-100%' will lower the element to where the baseline of the next line should have been.

5.4.5    'text-transform'

Value: capitalize | uppercase | lowercase | none
Initial: none
Applies to: all elements
Inherited: yes
Percentage values: N/A

uppercases the first character of each word
uppercases all letters of the element
lowercases all letters of the element
neutralizes inherited value.
The actual transformation in each case is human language and UA dependent.
  H1 { text-transform: uppercase }

The example above would put 'H1' elements in uppercase text.

5.4.6    'text-align'

Value: left | right | center | justify
Initial: UA specific
Applies to: block-level elements
Inherited: yes
Percentage values: N/A

This property describes how text is aligned within the element. The actual justification algorithm used is UA and human language dependent.


  DIV.center { text-align: center }

Since this property inherit, all block-level elements inside the 'DIV' element with 'CLASS=center' will be centered. Note that alignments are relative to the width of the element, not the canvas. If 'justify' is not supported, the UA will supply a replacement. Typically, this will be 'left' for western languages.

5.4.7    'text-indent'

Value: <length> | <percentage>
Initial: 0
Applies to: block-level elements
Inherited: yes
Percentage values: refer to parent element's width

The property specifies indent that appears before the first formatted line. 'text-indent' may be negative, but there may be implementation-specific limits. An indent is not inserted in the middle of an element that was broken by another (such as 'BR' in HTML).


 P { text-indent: 3em }

5.4.8    'line-height'

Value: <number> | <length> | <percentage>
Initial: UA specific
Applies to: all elements except replaced elements
Inherited: yes
Percentage values: relative to the font size of the element itself

The property sets the the distance between two adjacent lines' baselines.

When a numerical value is specified, the line height is given by the font size of the current element multiplied with the numerical value. This differs from a percentage value in the way it inherits: when a numerical value is specified, child elements will inherit the factor itself, not the resultant value (as is the case with percentage and other units).

Negative values are not allowed.

The three rules in the example below have the same resultant line height:

  DIV { line-height: 1.2; font-size: 10pt }     /* number */
  DIV { line-height: 1.2em; font-size: 10pt }   /* length */
  DIV { line-height: 120%; font-size: 10pt }    /* percentage */

It is suggested that UAs set the initial value to be a number in the range of 1.0 to 1.2.

See the section 4.7 for a description on how 'line-height' influences the formatting of a block-level element.

5.5    Box properties

See the formatting model (section 4) for examples on how to use the box properties.

5.5.1    'margin-top', 'margin-right', 'margin-bottom', 'margin-left', 'margin'

Value: [ <length> | <percentage> | auto ]{1,4} (for 'margin' property)
Initial: 0
Applies to: all elements
Inherited: no
Percentage values: refer to parent element's width

These properties set the margin of an element: the 'margin' property sets the border for all four sides while the other properties only set their respective side.

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

  BODY { margin: 2em } /* all margins set to 2em */
  BODY { margin: 1em 2em } /* top & bottom = 1em, right & left = 2em */
  BODY { margin: 1em 2em 3em } /* top=1em, right=2em, bottom=3em, left=2em */

The 'margin' property is shorthand for setting 'margin-top', 'margin-right' 'margin-bottom' and 'margin-left' at the same place in the style sheet. These properties allow only one value. The last rule of the example above is equivalent to the example below:

  BODY {
    margin-top: 1em;
    margin-right: 2em;
    margin-bottom: 3em;
    margin-left: 2em;        /* copied from opposite side (right) */

The margins express the minimal distance between the borders of two adjacent elements. See the formatting model (section 4) for an example.

When margin properties are applied to replaced elements (e.g. IMG), they express the minimal distance from the replaced element to any of the content of the parent element.

Negative margin values are allowed, but there may be implementation-specific limits.

5.5.2    'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'padding'

Value: [ <length> | <percentage> | auto ]{1,4} (for 'padding' only)
Initial: 0
Applies to: all elements
Inherited: no
Percentage values: refer to parent element's width

These properties describe how much space to insert between the border and the content (e.g. text or image). The 'padding' property sets the border for all four sides while the other properties only set their respective side.

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

The surface of the padding area is set with the 'background' property:

  H1 { 
    background: white; 
    padding: 1em 2em;

The example above sets a '1em' padding vertically ('padding-top' and 'padding-bottom') and a '2em' padding horizontally ('padding-right' and 'padding-left'). The 'em' unit is relative to the element's font size.

Padding values cannot be negative. See the formatting model (section 4) for more on these properties.

5.5.3    'border-top', 'border-right', 'border-bottom', 'border-left', 'border'

Value: <border-width> || <border-style> || <color>
Initial: medium none
Applies to: all elements
Inherited: no
Percentage values: N/A

These properties set the border of an element: the 'border' property sets the border for all four sides while the other properties only set their respective side.

The border is drawn in the color specified. If no color value is specified, the value of the 'color' property of the element itself will take its place:

  P { 
    color: black; 
    background: white; 
    border: solid;

In the above example, the border will be a solid black line.

Possible values are: [thin | medium | thick | <length>]. If not specified, 'medium' is assumed. The width of the keyword values are UA dependent, but the following holds: 'thin' <= 'medium' <= 'thick'.

The keyword widths are constant throughout a document:

  H1 { border: solid thick red }
  P  { border: solid thick blue }

In the example above, 'H1' and 'P' elements will have the same border width regardless of font size. To do relative width, the 'em' unit can be used:

  H1 { border: solid 0.5em }
Possible values are: [ none | dotted | dashed | solid | double | groove | ridge | inset | outset ]. If no value is specified, 'none' is assumed.

The border styles mean:

no border is drawn (regardless of any <border-width>)
the border is a dotted line drawn on top of the background of the element
the border is a dashed line drawn on top of the background of the element
the border is a solid line
the border is a double line drawn on top of the background of the element. The sum of the two single lines and the space between equals the <border-width> value.
a 3D groove is drawn in the <color> value.
a 3D ridge is drawn in colors based on the <color> value.
a 3D inset is drawn in colors based on the <color> value.
a 3D outset is drawn in colors based on the value.

If the element is 'inline' and spans several lines, the UA is free to render one border on each line, possibly with omitted edges.

5.5.4    'width'

Value: <length> | <percentage> | auto
Initial: auto, except for elements with an intrinsic dimension
Applies to: block-level and replaced elements
Inherited: no
Percentage values: refer to parent element's width

This property can be applied to text elements, 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 ratio of the image should be preserved if the 'height' property is 'auto'.


  IMG.icon { width: 100px }

See the formatting model (section 4) for a description of the relationship between this property and the margin and padding.

5.5.5    'height'

Value: <length> | auto
Initial: auto
Applies to: block-level and replaced elements
Inherited: no
Percentage values: N/A

This property can be applied to text, but it is most useful with inline images and similar insertions. The height is to be enforced by scaling the image if necessary. When scaling, the aspect ratio of the image should be preserved if the 'width' property is 'auto'.


  IMG.icon { height: 100px }

If applied to a textual element, the height can be enforced with e.g. a scrollbar.

5.5.6    'float'

Value: left | right | none
Initial: none
Applies to: all elements
Inherited: no
Percentage values: N/A

With the value 'none', the element will be displayed where it appears in the text. With a value of 'left' ('right') the margin properties will decide the horizontal positioning of the image and the text will float on the right (left) side of the image. With a a value of 'left' or 'right', the element is treated as block-level (i.e. the 'display' property is ignored).

  IMG.icon { 
    float: left;
    margin-left: 0;

The above example will place all IMG elements with 'CLASS=icon' along the left side of the parent element.

A value of 'right' will change the way default

This property is most often used with inline images.

5.5.7    'clear'

Value: none | left | right | both
Initial: none
Applies to: all elements
Inherited: no
Percentage values: N/A

This property specifies if an element allows floating elements on its sides. More specifically, the value of this property lists the sides where floating elements are not accepted. With 'clear' set to 'left', an element will be moved below any floating element on the left side. With 'clear' set to 'none', floating elements are allowed on all sides. Example:

  H1 { clear: left }

5.6    Classification properties

These properties classify elements into categories more than they set specific visual parameters.

5.6.1    'display'

Value: block | inline | list-item | none
Initial: according to HTML
Applies to: all elements
Inherited: no
Percentage values: N/A

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

A value of 'none' turns the display of the element, including children elements and the surrounding box, off.

  P { display: block }
  EM { display: inline }
  LI { display: list-item }
  IMG { display: none }

The last rule turns the display of images off.

Note that HTML defines what elements are block-level (called "Block Structuring Elements" in [2]) and inline (called "Phrase Markup" in [2]), and this may be hardcoded into some UA implementations.

5.6.2    'list-style'

Value: <keyword> || <position> || <url>
Initial: disc outside
Applies to: elements with 'display' property value 'list-item'
Inherited: yes
Percentage values: N/A

The 'list-style' property describes how list items (i.e. elements with a 'display' value of 'list-item') are formatted.

Possible values are: [disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none]. If no value is specified, 'disc' is assumed.
The value of <position> is determines how the list item marker is drawn with regard to the content. Possible values are: [ inside | outside ]. If no value is specified, 'outside' is assumed.

This property can be set on any element, and it will inherit normally down the tree. However, the 'list-style' will only be displayed on elements with a 'display' value of 'list-item'. In HTML this is typically the case for the 'LI' element.

  UL { list-style: disc inside }
  UL UL { list-style: circle outside }
  LI.square { list-style: square }
  OL { list-style: decimal }       /* 1 2 3 4 5 etc. */
  OL { list-style: lower-alpha }   /* a b c d e etc. */
  OL { list-style: lower-roman }   /* i ii iii iv v etc. */

Setting 'list-style' directly on 'LI' elements can have unexpected results. Consider:

  OL.alpha LI  { list-style: lower-alpha }
  UL LI        { list-style: disc }

Since the specificity (as defined in the cascading order) is higher for the first rule in the example above, it will override the second rule on all 'LI' elements and only 'lower-alpha' list styles will be used. It is therefore recommended to set 'list-style' only on the list type elements:

  OL.alpha  { list-style: lower-alpha }
  UL        { list-style: disc }

In the above example, inheritance will transfer the 'list-style' values from 'OL' and 'UL' elements to 'LI' elements.

A URL value can be combined with any other value:

  UL { list-style: url(http://png.com/ellipse.png) disc }

In the example above, the 'disc' will be used when the image is unavailable.

An example of an 'outside' rendering:

  * first list item 
    comes first

  * second list item
    comes second

The same example formatted with 'inside':

  * first list
  item comes first

  * second list
  item comes second

5.6.3    'white-space'

Value: normal | pre | nowrap
Initial: according to HTML
Applies to: block-level elements
Inherited: yes
Percentage values: N/A

This property declares how white space inside the element should be handled: the 'normal' way (where white space is collapsed), as 'pre' (which behaves like the 'PRE' element in HTML) or as 'nowrap' (where wrapping is done only through BR elements):

  PRE { white-space: pre }
  P   { white-space: normal }

6    Units

6.1    Length units

The format of a length value is an optional sign character ('+' or '-', with '+' being the default) immediately followed by a number (with or without a decimal point) immediately followed by a unit identifier (a two-letter abbreviation). After a '0' number, the unit identifier is optional.

Some properties allow negative length units, but this may complicate the formatting model and there may be implementation-specific limits. If a negative length value cannot be supported, it should be clipped to the nearest value that can be supported.

There are two types of length units: relative and absolute. Relative units specify a length relative to another length property. Style sheets that use relative units will more easily scale from one medium to another (e.g. from a computer display to a laser printer). Percentage units (described below) and keyword values (e.g. 'x-large') offer similar advantages.

These relative units are supported:

  H1 { margin: 0.5em }      /* ems, the height of the element's font */
  H1 { margin: 1ex }        /* x-height, ~ the height of the letter 'x' */
  P  { font-size: 12px }    /* pixels, relative to canvas */

The relative units 'em' and 'ex' are relative to the font size of the element itself. The only exception to this rule in CSS1 is the 'font-size' property where 'em' and 'ex' values refer to the font size of the parent element.

Pixel units, as used in the last rule, are relative to the resolution of the canvas, i.e. most often a computer display. If the pixel density of the output device is very different from that of a typical computer display, the UA should rescale pixel values. The suggested "reference pixel" is the visual angle of one pixel on a device with a pixel density of 90dpi and a distance from the reader of an arm's length.

Child elements inherit the computed value, not the relative value:

  BODY {
    font-size: 12pt;
    text-indent: 3em;  /* i.e. 36pt */
  H1 { font-size: 15pt }

In the example above, the 'text-indent' value of 'H1' elements will be 36pt, not 45pt.

Absolute length units are only useful when the physical properties of the output medium is known. These absolute units are supported:

  H1 { margin: 0.5in }      /* inches, 1in = 2.54cm */
  H2 { line-height: 3cm }   /* centimeters */
  H3 { word-spacing: 4mm }  /* millimeters */
  H4 { font-size: 12pt }    /* points, 1pt = 1/72 in */
  H4 { font-size: 1pc }     /* picas, 1pc = 12pt */

In cases where the specified length cannot be supported, UAs should try to approximate. For all CSS1 properties, further computations and inheritance should be based on the approximated value.

6.2    Percentage units

The format of a length value is a number (with or without a decimal point) immediately followed by '%'.

Percentage values are always relative to a length unit. Each property that allows percentage units also define what length unit they refer to. Most often this is the font size of the element itself:

  P { line-height: 120% }   /* 120% of the element's 'font-size' */

In all CSS1 properties, child elements inherit the resultant value, not the percentage value.

6.3    Color units

A color is a either a color name or a numerical RGB specification.

The suggested list of color names is: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. These 16 colors are taken from the Windows VGA palette and will also be used in forthcoming HTML 3.2. The RGB values for these color name are not defined in this specification.

  BODY {color: black; background: white }
  H1 { color: maroon }
  H2 { color: olive }

The RGB color model is being used in numerical color specifications. There are different ways to specify red:

There are different ways to specify red:

  EM { color: #f00 }              /* #rgb */
  EM { color: #ff0000 }           /* #rrggbb */
  EM { color: rgb(255,0,0) }      /* integer range 0 - 255 */
  EM { color: rgb(255,0,0) }      /* integer range 0 - 255 */
  EM { color: rgb(100%, 0%, 0%) } /* float range 0.0% - 100.0% */

Note that the three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00.

RGB colors are specified in the sRGB color space as defined in the appendix of [6]. UAs should make reasonable efforts to render colors accurately according to the sRGB specification.

Values outside the numerical ranges should be clipped. The three rules below are therefore equivalent:

  EM { color: rgb(255,0,0) }       /* integer range 0 - 255 */
  EM { color: rgb(300,0,0) }       /* clipped to 255 */
  EM { color: rgb(110%, 0%, 0%) }  /* clipped to 100% */

6.4    URL

A Uniform Resource Locator (URL) is identified with a functional notation:

  BODY { background: url(http://www.bg.com/pinkish.gif) }

Partial URLs are interpreted relative to the source of the style sheet, not relative to the document:

  BODY { background: url(yellow) }

7    CSS1 conformance

W3C will publish a test suite of HTML documents with CSS1 style sheets that conforming UAs must format correctly. A UA conforms to the CSS1 specification if it passes the test suite. The test suite will ensure that a conforming UA:

Example of constraints of the presentation medium are: limited resources (fonts, color) and limited resolution (so margins may not be accurate). In these cases, the UA should approximate the style sheet values. Also, different user interface paradigms may have their own constraints: a VR browser may rescale the document based on its "distance" from the user.

UAs may offer readers the ability to set additional constraints on the presentation medium, e.g., to deal with visual impairments or to disable blinking.

Note that CSS1 does not specify all aspects of formatting. E.g., the UA is free to select a letter-spacing algorithm.

This specification also recommends, but doesn't require, that a UA:

The above conformance rules only describe functionality, not user interface.

7.1    Forward-compatible grammar

This section and the next describe a "meta-syntax", in the sense that they define the limits within which CSS1 and all future extensions will have to remain. In other words, the CSS1 language is a subset of the language described here, and all later versions of CSS are intended to be subsets of that language as well. Implementors should create parsers that are "forward compatible": when unknown constructions are encountered, the text below tells the parser how much of the input can be safely skipped.

Here is an EBNF-like grammar:

stylesheet   : CDO? rules? CDC?
rules        : [ at-rule | rule ]+
rule         : selector decl-block
at-rule      : AT_KEYWORD token* [ ';' | decl-block | rule-block ]
selector     : token+
decl-block   : '{' declarations '}'
rule-block   : '{' rules '}'
declarations : declaration? [ ';' declaration? ]*
declaration  : IDENT ':' token+
token        : IDENT | '[' token* ']' | '(' token* ')' |
               SYMBOL | ':' | ',' | STRING | NUMBER | DIM

Note that this grammar is not LL(1); in practice, it will depend on the AT_KEYWORD whether an at-rule ends with a semicolon, a decl-block or a rule-block.

In English, the grammar says: a style sheet is a list of rules (normal rules or @-rules), each rule ends either with a semicolon (;) or with a block ({...}). Blocks contain either declarations (keyword-colon-value), or they contain more rules, in which case they may be nested. Note that nested blocks are not used in CSS1.

The style sheet may be enclosed in <!-- and -->, which is useful when it is embedded in an HTML document.

Besides the 9 punctuation characters ( , : ; [ ] ( ) { } ), the lexical tokens of CSS are:

IDENT       : namestart namechar*
NUMBER      : [ '-' | '+' ]? decimal+
            | [ '-' | '+' ]? decimal* '.' decimal+
STRING      : '"' [ stringchar | escape | sq ]* '"'
            | sq [ stringchar | escape | '"' ]* sq
WS          : whitespace+
CDO         : '<' '!' '-' '-'
CDC         : '-' '-' '>'
SYMBOL      : symchar+

Using the following auxiliary definitions:

symchar     : '`' | '~' | '!' | '@' | '#' | '$' | '%' | '^' | '&' |
              '*' | '-' | '_' | '+' | '=' | '|' | '<' | '>' | '.' |
              '/' | '?'
stringchar  : <any printable character except ' and " including space>
decimal     : '0' | ... | '9'
octal       : '0' | ... | '7'
sq          : <a single quote: ' >
namestart   : letter | latin1 | escape
namechar    : letter | latin1 | escape | decimal | '-'
letter      : 'A' | ... | 'Z' | 'a' | ... | 'z'
latin1      : <a Latin 1 character (codes 161-255)>
escape      : unicode | '\' printable
unicode     : '\' octal [ octal [ octal [ octal [ octal octal? ]? ]? ]? ]?
printable   : <any printable character including space>
whitespace  : <tab> | <space> | <newline> | comment
comment     : '/' '*' any* '*' '/'
any         : <any character>

These definitions assume the Latin 1 character set. Future versions of CSS may widen some of them to allow Unicode characters.

Paraphrased in English:

a sequence of letters, digits, dashes and backslash-escapes, not starting with a dash or a digit
an identifier preceded by an @-sign
a (possibly signed) sequence of digits, with at most one decimal point, which may not be at the start
a number with a unit
a sequence of printable characters, spaces or backslash escapes, between double quotes, not containing double quotes (unless escaped); or:
ditto between single quotes, not containing single quotes (unless escaped)
a sequence of whitespace characters (spaces, tabs, newlines)
"<!--" and "-->"
{ } ( ) [ ] , ; :
any sequence of other punctuation characters

In case of ambiguity, take the longest match, except for comments.

7.2    Parsing conventions

In order for CSS implementations to be interoperable, as well as being prepared for future extensions to CSS, a conforming UA should follow these parsing conventions:

Note: The CLASS attribute of HTML allows more characters in a class name than the set allowed for selectors above. In CSS level 1, these characters have to be escaped or written as Unicode numbers: "B&W?" can be written as "B\&W\?" or "B\46W\77", "κουρος" (Greek: "kouros") has to be written as "\1710\1677\1705\1701\1677\1702". It is expected that in later versions of CSS more characters can be entered directly.

As a help to implementers, a more detailed grammar for CSS1 is included in appendix B.

8    References

[1] The W3C resource page on web style sheets (http://www.w3.org/pub/WWW/Style)

[2] RFC 1866: Hypertext Markup Language - 2.0, (ftp://ds.internic.net/rfc/rfc1866.txt). The specification is also available in hypertext form (http://www.w3.org/pub/WWW/MarkUp/html-spec/html-spec_toc.html)

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

[4] HTML3 and Style Sheets (http://www.w3.org/pub/WWW/TR/WD-style.html)

[5] HyperText Markup Language Specification Version 3.0 (http://www.w3.org/pub/WWW/MarkUp/html3/CoverPage.html). The draft has now expired

[6] M Anderson, R Motta, S Chandrasekar, M Stokes: Proposal for a Standard Color Space for the Internet - sRGB (http://www.w3.org/pub/WWW/Printing/motta/W3Color.html)

[7] T Berk, L Brownston, A Kaufman: A New Color-Naming System for Graphics Languages, IEEE CG&A, May 1982

[8] DSSSL (http://occam.sjf.novell.com:8080/dsssl/dsssl96) is a tree transformation and style language from the SGML community. Bert Bos has written some notes on Translating CSS to DSSSL (http://www.w3.org/pub/WWW/Style/css/css2dsssl.html)

[9] Frame-based layout via Style Sheets (http://www.w3.org/pub/WWW/TR/WD-layout.html)

[10] PNG (Portable Network Graphics) Specification (http://www.w3.org/pub/WWW/TR/WD-png.html)

[11] F Yergeau, G Nicol, G Adams, M Dürst: Internationalization of the Hypertext Markup Language (ftp://ietf.org/internet-drafts/draft-ietf-html-i18n-05.txt)

9    Acknowledgments

During the short life of HTML, there have been several style sheet proposals to which this proposal is indebted. Especially the proposals from Robert Raisch, Joe English and Pei Wei were influential.

Through "www-style@w3.org" and other electronic media, these people have contributed: Kevin Hughes, William Perry, Benjamin Sittler, Tony Jebson, Paul Prescod, Evan Kirshenbaum, Scott Bigham, Glenn Adams, Scott Preece, Greg Watkins, Jon Smirl, Jenny Raggett, Michael Seaton, Charles Peyton Taylor, Lauren Wood, David Seibert, Donna Converse, Wayne Gramlich, Murray Altheim and Liam Quin.

Also, thanks to Tim Berners-Lee, Vincent Quint, Cécile Roisin, Irène Vatton, Phill Hallam-Baker, Yves Lafon, Yves Bertot, Colas Nahaboo, Philippe Kaplan, Gilles Kahn, Terry Allen, Daniel Connolly, Roy Fielding, Henrik Frystyk Nielsen, James Clark, David Siegel, Thomas Reardon, Chris Wilson, Lydja Williams, Mandira Virmani, Scott Isaacs, Robert Cailliau, Stephen Zilles, Mike Wexler, Daniel Veillard, Lou Montulli, Phil Karlton for constructive discussions.

Three people deserve special mentioning: Dave Raggett (for his encouragement and work on HTML3), Chris Lilley (for his continued contributions, especially in the area of colors and fonts) and Steven Pemberton (for his organizational as well as creative skills).

Appendix A: Sample style sheet for HTML 2.0

The following style sheet is written according to the suggested rendering in the HTML 2.0 specification. Some styles, e.g. colors, have been added for completeness. It is suggested that a style sheet similar to the one below is used as a UA default.

  BODY { 
    margin: 1em;
    font-family: serif;
    line-height: 1.1;
    background: white;
    color: black; 

  H1, H2, H3, H4, H5, H6, P, UL, OL, DIR, MENU, DIV, 
  DT, DD, ADDRESS, BLOCKQUOTE, PRE, BR, HR { display: block }

  IMG, SPAN { display: inline }

  LI { display: list-item }

  H1, H2, H3, H4 { margin-top: 1em; margin-bottom: 1em }
  H5, H6 { margin-top: 1em }
  H1 { text-align: center }
  H1, H2, H4, H6 { font-weight: bold }
  H3, H5 { font-style: italic }

  H1 { font-size: xx-large }
  H2 { font-size: x-large }
  H3 { font-size: large }

  B, STRONG { font-weight: bolder }  /* relative to the parent */
  I, CITE, EM, VAR, ADDRESS, BLOCKQUOTE { font-style: italic }
  PRE, TT, CODE, KBD, SAMP { font-family: monospace }

  PRE { white-space: pre }

  ADDRESS { margin-left: 3em }
  BLOCKQUOTE { margin-left: 3em; margin-right: 3em }

  UL, DIR { list-style: disc }
  OL { list-style: decimal }
  MENU { margin: 0 }              /* tight formatting */
  LI { margin-left: 3em }

  DT { margin-bottom: 0 }
  DD { margin-top: 0; margin-left: 3em }

  HR { border-top: solid }        /* 'border-bottom' could also have been used */

  A:link { color: blue }          /* unvisited link */
  A:visited { color: red }        /* visited links */
  A:active { color: lime }        /* active links */

  /* setting the anchor border around IMG elements
     requires contextual selectors */

  A:link IMG { border: 2px solid blue }
  A:visited IMG { border: 2px solid red }
  A:active IMG { border: 2px solid lime }

Appendix B: A sample lex/yacc grammar

The minimal CSS grammar that all implementations need to support is defined in section 7. However, that grammar is not very helpful when implementing CSS1. Hopefully, the yacc/lex grammar below better serves that purpose.

The format of the productions is optimized for human consumption and some shorthand notation beyond yacc is used:

  *  : 0 or more
  +  : 1 or more
  ?  : 0 or 1
  |  : separates alternatives
  [] : grouping 

The productions are:

 : CDO? import* rule* CDC?
 : IMPORT_SYM [STRING|URL] ';'		/* E.g., @import url(fun.css); */
 : '-' | '+'
         * The only operators in level 1 are slash, space and comma.
         * An expression `a b c, d e f' stands for a list
         * [[a,b,c],[d,e,f]]. Note that `a,b,c' is the list
         * [a,b,c], *not* [[a],[b],[c]].
 : '/' | ',' | /* empty */
 : selector [ ',' selector ]*
   '{' declaration [ ';' declaration ]* '}'
 : simple_selector+ [ ':' pseudo_element ]?
         * A simple_selector is something like H1, PRE.FOO,
         * .FOO, etc., or it is an ID: #p004
         * DOT_WO_WS is a `.' without preceding whitespace.
         * DOT_W_WS is a `.' with preceding whitespace.
 : element_name pseudo_class? [ DOT_WO_WS class ]?
 | DOT_W_WS class
 | id_selector
 : '#' IDENT
 : property ':' expr prio? 
 | /* empty */				/* Prevents syntax errors... */
 : IMPORTANT_SYM	 		/* !important" */
 : term [ operator term ]*
 : unary_operator?

The following is the input to a lex/flex scanner. Note that this assumes an 8-bit implementation of (f)lex.

#include "constants.h"
    The constants include definitions similar to the following:
    #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
unicode		\\[0-7]{1,6}
latin1		[¡-]
escape		{unicode}|\\[ -~¡-]
stringchar	{escape}|{latin1}|[ !#$%&(-~]
nmstrt		[a-zA-Z]|{latin1}|{escape}
nmchar		[-a-zA-Z0-9]|{latin1}|{escape}
ident		{nmstrt}{nmchar}*
d		[0-9]
notnm		[^-a-zA-Z0-9\\]|{latin1}
w		[ \t\n]*
num		{d}+|{d}*\.{d}+
h		[0-9a-fA-F]
h3		{h}{h}{h}
h6		{h3}{h3}
h9		{h3}{h3}{h3}

"/*"			{BEGIN(COMMENT);}
<COMMENT>\n		{/* ignore */}
<COMMENT>.		{/* ignore */}
@import			return IMPORT_SYM;
"!"{w}important		return IMPORTANT_SYM;
{ident}			{yylval.sym = str2Symbol(yytext); return IDENT;}
\"({stringchar}|\')*\"  |
\'({stringchar}|\")*\'  {yylval.str = noquotes(yytext); return STRING;}
{num}			{yylval.num = atof(yytext); return NUMBER;}
{num}"%"		{yylval.num = atof(yytext); return PERCENTAGE;}
{num}pt/{notnm}		{yylval.num = atof(yytext) * POINT; return LENGTH;}
{num}mm/{notnm}		{yylval.num = atof(yytext); return LENGTH;}
{num}cm/{notnm}		{yylval.num = atof(yytext) * CM; return LENGTH;}
{num}pc/{notnm}		{yylval.num = atof(yytext) * PICA; return LENGTH;}
{num}in/{notnm}		{yylval.num = atof(yytext) * INCH; return LENGTH;}
{num}px/{notnm}		{yylval.num = atof(yytext) * pixelwd; return LENGTH;}
{num}em/{notnm}		{yylval.num = atof(yytext); return EMS;}
{num}ex/{notnm}		{yylval.num = atof(yytext); return EXS;}
":"link			{return LINK_PSCLASS;}
":"visited		{return VISITED_PSCLASS;}
":"active		{return ACTIVE_PSCLASS;}
"#"{h9}			|
"#"{h6}			|
"#"{h3}			{yylval.str = yytext; return HEXCOLOR;}
"url("[^\n)]+")"	{yylval.str = noquotes(yytext+3); return URL;}
"rgb("{w}{num}%?{w},{w}{num}%?{w},{w}{num}%?"{w})"	{yylval.str = yytext; return RGB;}
":"			return ':';
^"."			|
[ \t]+"."		return DOT_W_WS;
"."			return DOT_WO_WS;
"/"			return '/';
"+"			return '+';
"-"			return '-';
"{"			return '{';
"}"			return '}';
";"			return ';';
","			return ',';
"#"			return '#';
[ \t]+			{/* ignore whitespace */}
\n			{/* ignore whitespace */}
\<\!\-\-                return CDO;
\-\-\>                  return CDC;
.			{yyerror("Illegal character");}

Appendix C: Encoding

HTML documents may contain any of the about 30,000 different characters defined by Unicode. Many documents only need a few hundred. Many fonts also only contain just a few hundred glyphs. In combination with section 5.2, this appendix explains how the characters in the document and the glyphs in a font are matched.

Character encoding

The content of an HTML document is a sequence of characters and markup. To send it "over the wire", it is encoded as a sequence of bytes, using one of several possible encodings. The HTML document has to be decoded to find the characters. For example, in Western Europe it is customary to use the byte 224 for an a-with-grave-accent (à), but in Hebrew, it is more common to use 224 for an Aleph. In Japanese, the meaning of a byte usually depends on the bytes that preceded it. In some encodings, one character is encoded as two (or more) bytes.

The UA knows how to decode the bytes by looking at the "charset" parameter in the HTTP header. Typical encodings (charset values) are "ASCII" (for English), "ISO-8859-1" (for Western Europe), "ISO-8859-8" (for Hebrew), "Shift-JIS" (for Japanese).

HTML (assuming the HTML-i18n document [11] is adopted), allows some 30,000 different characters, namely those defined by Unicode. Not many documents will use that many different characters, and choosing the right encoding will usually ensure that the document only needs one byte per character. Occasional characters outside the encoded range can still be entered as numerical character references: '&#928;' will always mean the Greek uppercase Pi, no matter what encoding was used. Note that this entails that UAs have to be prepared for any Unicode character, even if they only handle a few encodings.

Font encoding

A font doesn't contain characters, it contains pictures of characters, known as glyphs. The glyphs, in the form of outlines or bitmaps, constitute a particular representation of a character. Either explicitly or implicitly, each font has a table associated with it, the font encoding table, that tells for each glyph what character it is a representation for. In Type 1 fonts, the table is referred to as an encoding vector.

In fact, many fonts contain several glyphs for the same character. Which of those glyphs should be used depends either on the rules of the language, or on the preference of the designer.

In Arabic, for example, all letters have four different shapes, depending on whether the letter is used at the start of a word, in the middle, at the end, or in isolation. It is the same character in all cases, and thus there is only one character in the HTML document, but when printed, it looks differently each time.

There are also fonts that leave it to the graphic designer to choose from among various alternative shapes provided. Unfortunately, CSS1 doesn't yet provide the means to select those alternatives. Currently, it is always the default shape that is chosen from such fonts.

Font sets

To deal with the problem that a single font may not be enough to display all the characters in a document, or even a single element, CSS1 allows the use of font sets.

A font set in CSS1 is a list of fonts, all of the same style and size, that are tried in sequence to see if they contain a glyph for a certain character. An element that contains English text mixed with mathematical symbols may need a font set of two fonts, one containing letters and digits, the other containing mathematical symbols. See section 5.2 for a detailed description of the selection mechanism for font sets.

Here is an example of a font set suitable for a text that is expected to contain text with Latin characters, Japanese characters, and mathematical symbols:

  BODY { font-family: Baskerville, Mincho, Symbol, serif }

The characters available in the Baskerville font (a font with only Latin characters) will be taken from that font, Japanese will be taken from Mincho, and the mathematical symbols will come from Symbol. Any other characters will (hopefully) come from the generic font family 'serif'. The 'serif' font family will also be used if one or more of the other fonts is unavailable.

Appendix D: The applicability and extensibility of CSS1

The goal of the work on CSS1 has been to create a simple style sheet mechanism for HTML documents. The current specification is a balance between the simplicity needed to realize style sheets on the web, and pressure from authors for richer visual control. CSS1 offers:

CSS1 does not offer:

We expect to see extensions of CSS in several directions:

We do not expect CSS to evolve into: