W3C

CSS Styling Attributes Level 1

W3C Working Draft 21 January 2010

This version:
http://www.w3.org/TR/2010/WD-css-style-attr-20100121/
Latest version:
http://www.w3.org/TR/css-style-attr
Previous version:
http://www.w3.org/TR/2002/WD-css-style-attr-20020515
Editor:
Elika J. Etemad
Previous Editors:
Tantek Çelik (Microsoft), <tantekc@microsoft.com>
Bert Bos (W3C), <bert@w3.org>
Marc Attinasi (AOL/Netscape), <attinasi@netscape.com>

Abstract

Markup languages such as HTML [HTML40] and SVG [SVG11] provide a styling attribute on most elements, to hold a fragment of a style sheet that applies to those elements. One of the possible style sheet languages is CSS. This draft describes the syntax and interpretation of the CSS fragment that can be used in such styling attributes.

Status of this document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-style-attr” in the subject, preferably like this: “[css-style-attr] …summary of comment…

This document was produced by the CSS Working Group (part of the Style Activity).

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This specification is a Last Call Working Draft. All persons are encouraged to review this document and send comments to the www-style mailing list as described above. The deadline for comments is 9 February 2010.

A CSS Styling Attribute Test Suite will be developed during the Candidate Recommendation phase of this CSS Styling Attribute specification.

Table of contents

1. Introduction

Some document formats have a styling attribute to permit the author to directly apply style information to specific elements in documents. If a document format defines a styling attribute and the attribute accepts CSS as its value, then this specification defines that CSS styling attribute’s syntax and interpretation.

The following example shows the use of the style attribute in HTML [HTML40]:

<p style="color: #090; line-height: 1.2">...</p>

2. Conformance

A document or implementation cannot conform to CSS Styling Attributes Level 1 alone, but can claim conformance to CSS Styling Attributes Level 1 if it satisfies the conformance requirements in this specification when implementing CSS together with styling attribute handling as defined in a document language that has CSS styling attributes.

Conformance to CSS Styling Attributes Level 1 is defined for two classes:

document
A document represented in a document language that defines a styling attribute for one or more of its elements.
interpreter
Someone or something that interprets the semantics of a document and its associated style information. (Most CSS user agents fall under this category.)

The conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification. All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word "Note" and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

3. Syntax and Parsing

The value of the styling attribute must match the syntax of the contents of a CSS declaration block, whose formal grammar is given below in terms of the CSS core grammar:

declaration-list
  : S* declaration? [ ';' S* declaration? ]*
  ;

Note that following the CSS2.1 convention, comment tokens are not shown in the rule above.

The interpreter must parse the styling attribute's value using the same forward-compatible parsing rules that apply to parsing declaration block contents in a normal CSS style sheet. See chapter 4 of the CSS2.1 specification for details. [CSS21]

Note that because there is no open brace delimiting the declaration list in the CSS styling attribute syntax, a close brace (}) in the styling attribute's value does not terminate the style data: it is merely an invalid token.

4. Cascading and Interpretation

The declarations in a styling attribute apply to the element to which the attribute belongs. CSS2.1 defines how style sheets and styling attributes are cascaded together. [CSS21] Relative URLs in the style data must be resolved relative to the styling attribute's element (or to the document if per-element resolution is not defined) when the attribute's value is parsed.

Aside from the differences in cascading, the declarations in a styling attribute must be interpreted exactly as if they were given in a CSS style rule that applies to the element.

The CSS Working Group strongly recommends that document languages do not allow multiple CSS styling attributes on a single element. If a document language allows multiple CSS styling attributes, each must be parsed independently and treated as a separate style rule, the ordering of which should be defined by the document language, else is undefined.

5. Acknowledgments

Thanks to feedback from Daniel Glazman, Ian Hickson, Eric A. Meyer, Björn Höhrmann.

6. References

Normative references

[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 8 September 2009. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2009/CR-CSS2-20090908
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt

Informative references

[HTML40]
Ian Jacobs; David Raggett; Arnaud Le Hors. HTML 4.0 Specification. 24 April 1998. W3C Recommendation. URL: http://www.w3.org/TR/1998/REC-html40-19980424
[SVG11]
Dean Jackson; 藤沢 淳; Jon Ferraiolo. Scalable Vector Graphics (SVG) 1.1 Specification. 14 January 2003. W3C Recommendation. URL: http://www.w3.org/TR/2003/REC-SVG11-20030114