Copyright © 2009 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
Markup languages such as HTML and SVG provide a "style" 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 of the CSS fragment that can be used in the "style" attribute.
This is a public copy of the editors' draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don't cite this document other than as 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.
Several XML-based document formats have a "style" attribute to permit the author to directly apply style information to specific elements in documents. If a document format defines a "style" attribute and the attribute accepts CSS as its value, then this specification describes the attribute's syntax and interpretation.
The following example shows the use of the style attribute
in HTML:
<p style="color: #090; line-height: 1.2">...</p>
The syntax of the style attribute syntax is exactly the same as the
contents of a CSS declaration
block. A close brace (}) in the style attribute value
does not terminate the style data; it is merely an invalid token.
The same rules for forward-compatible parsing apply to the inline style sheet as to a normal style sheet. See chapter 4 of the CSS2.1 specification. [CSS21]
The syntax of the CSS fragment that is allowed in the HTML "style" attribute can be formally specified as follows:
inline-stylesheet : S* declaration-list ; declaration-list : declaration [ ';' S* declaration ]* ;
Please refer to the grammar in appendix D of the CSS2.1 specification [CSS21] for the definition of the symbols not defined here.
The declarations in a style attribute apply to the element to which the attribute belongs. CSS2.1 defines how style sheets and "style" attributes are cascaded together. [CSS21] Aside from the differences in cascading, the declarations in a style attribute must be interpreted exactly as if they were given in a CSS style rule applied to the element.
The CSS Working Group strongly recommends that document languages do not allow multiple style attributes on a single element. If a document language allows multiple style attributes, each is parsed independently and treated as a separate style rule, the ordering of which should be defined by the document language, else is undefined.
A document or implementation cannot conform to CSS Style Attribute Syntax Level 1 alone, but can claim conformance to CSS Style Attribute Syntax Level 1 if it satisfies the conformance requirements in this specification when implementing CSS together with style attribute handling as defined in a document language that has style attributes.
Conformance to CSS Style Attribute Syntax Level 1 is defined for two classes:
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.
Thanks to feedback from Daniel Glazman, Ian Hickson, Eric A. Meyer, Björn Höhrmann.