This document formally specifies the core features of the CSS Object Model (CSSOM). Other documents in the CSSOM family of specifications as well as other CSS related specifications define extensions to these core features.
The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to and manipulation of style related state information and processes.
The features defined below are fundamentally based on prior specifications of the W3C DOM Working Group, primarily [DOM]. The purposes of the present document are (1) to improve on that prior work by providing more technical specificity (so as to improve testability and interoperability), (2) to deprecate or remove certain less-widely implemented features no longer considered to be essential in this context, and (3) to newly specify certain extensions that have been or expected to be widely implemented.
2. TerminologyThis specification employs certain terminology from the following documents: DOM, HTML, CSS Syntax, Encoding, URL, Fetch, Associating Style Sheets with XML documents and XML. [DOM] [HTML] [CSS3SYN] [ENCODING] [URL] [FETCH] [XML-STYLESHEET] [XML]
When this specification talks about object A
where A
is actually an interface, it generally means an object implementing interface A
.
The terms set and unset to refer to the true and false values of binary flags or variables, respectively. These terms are also used as verbs in which case they refer to mutating some value to make it true or false, respectively.
The term supported styling language refers to CSS.
Note: If another styling language becomes supported in user agents, this specification is expected to be updated as necessary.
The term supported CSS property refers to a CSS property that the user agent implements, including any vendor-prefixed properties, but excluding custom properties. A supported CSS property must be in its lowercase form for the purpose of comparisons in this specification.
In this specification the ::before and ::after pseudo-elements are assumed to exist for all elements even if no box is generated for them.
When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can’t change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
Unless otherwise stated, string comparisons are done in a case-sensitive manner.
2.1. Common Serializing IdiomsTo escape a character means to create a string of "\
" (U+005C), followed by the character.
To escape a character as code point means to create a string of "\
" (U+005C), followed by the Unicode code point as the smallest possible number of hexadecimal digits in the range 0-9 a-f (U+0030 to U+0039 and U+0061 to U+0066) to represent the code point in base 16, followed by a single SPACE (U+0020).
To serialize an identifier means to create a string represented by the concatenation of, for each character of the identifier:
-
" (U+002D), then the character escaped as code point.-
" (U+002D), and there is no second character, then the escaped character.-
" (U+002D) or "_
" (U+005F), or is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to U+005A), or [a-z] (U+0061 to U+007A), then the character itself.To
serialize a function func, returning a
string:
Let s be an empty string.
Serialize an identifier from func’s name, ASCII lowercased, and append the result to s.
Append "(" (U+0028) to s.
Serialize func’s contents, either as specified by the definition of func, or in the shortest form possible (akin to the principles captured by serialize a CSS value). Append the result to s.
Append ")" (U+0029) to s.
Return s.
To serialize a string means to create a string represented by '"' (U+0022), followed by the result of applying the rules below to each character of the given string, followed by '"' (U+0022):
\
" (U+005C), the escaped character.Note: "'
" (U+0027) is not escaped because strings are always serialized with '"' (U+0022).
To serialize a URL means to create a string represented by "url(
", followed by the serialization of the URL as a string, followed by ")
".
To serialize a LOCAL means to create a string represented by "local(
", followed by the serialization of the LOCAL as a string, followed by ")
".
To serialize a comma-separated list concatenate all items of the list in list order while separating them by ",
", i.e., COMMA (U+002C) followed by a single SPACE (U+0020).
To serialize a whitespace-separated list concatenate all items of the list in list order while separating them by "
", i.e., a single SPACE (U+0020).
Note: When serializing a list according to the above rules, extraneous whitespace is not inserted prior to the first item or subsequent to the last item. Unless otherwise specified, an empty list is serialized as the empty string.
3. CSSOMStringMost strings in CSSOM interfaces use the CSSOMString
type. Each implementation chooses to define it as either USVString
or DOMString
:
typedef USVString CSSOMString;
Or, alternatively:
typedef DOMString CSSOMString;
The difference is only observable from web content when
surrogatecode units are involved.
DOMString
would preserve them, whereas
USVString
would replace them with U+FFFD REPLACEMENT CHARACTER.
This choice effectively allows implementations to do this replacement, but does not require it.
Using USVString
enables an implementation to use UTF-8 internally to represent strings in memory. Since well-formed UTF-8 specifically disallows surrogate code points, it effectively requires this replacement.
On the other hand, implementations that internally represent strings as 16-bit code units might prefer to avoid the cost of doing this replacement.
Media queries are defined by [MEDIAQUERIES]. This section defines various concepts around media queries, including their API and serialization form.
4.1. Parsing Media QueriesTo parse a media query list for a given string s into a media query list is defined in the Media Queries specification. Return the list of media queries that the algorithm defined there gives.
Note: A media query that ends up being "ignored" will turn into "not all
".
To parse a media query for a given string s means to follow the parse a media query list steps and return null if more than one media query is returned or a media query if a single media query is returned.
Note: Again, a media query that ends up being "ignored" will turn into "not all
".
To serialize a media query list run these steps:
To serialize a media query let s be the empty string, run the steps below:
not
", followed by a single SPACE (U+0020), to s.all
" or if the media query is negated append type, followed by a single SPACE (U+0020), followed by "and
", followed by a single SPACE (U+0020), to s.(
" (U+0028), followed by the media feature name, converted to ASCII lowercase, to s.:
" (U+003A), followed by a single SPACE (U+0020), followed by the serialized media feature value, to s.)
" (U+0029) to s.and
", followed by a single SPACE (U+0020), to s.Here are some examples of input (first column) and output (second column):
Input Outputnot screen and (min-WIDTH:5px) AND (max-width:40px)
not screen and (min-width: 5px) and (max-width: 40px)
all and (color) and (color)
(color) and (color)4.2.1. Serializing Media Feature Values
This should probably be done in terms of mapping it to serializing CSS values as media features are defined in terms of CSS values after all.
To serialize a media feature value named v locate v in the first column of the table below and use the serialization format described in the second column:
Other specifications can extend this table and vendor-prefixed media features can have custom serialization formats as well.
4.3. Comparing Media QueriesTo compare media queries m1 and m2 means to serialize them both and return true if they are a case-sensitive match and false if they are not.
4.4. TheMediaList
Interface
An object that implements the MediaList
interface has an associated collection of media queries.
[Exposed=Window] interfaceMediaList
{ stringifier attribute [LegacyNullToEmptyString] CSSOMString mediaText; readonly attribute unsigned long length; getter CSSOMString? item(unsigned longindex
); undefined appendMedium(CSSOMStringmedium
); undefined deleteMedium(CSSOMStringmedium
); };
The object’s supported property indices are the numbers in the range zero to one less than the number of media queries in the collection of media queries represented by the collection. If there are no such media queries, then there are no supported property indices.
To create a MediaList
object with a string text, run the following steps:
MediaList
object.mediaText
attribute to text.MediaList
object.The mediaText
attribute, on getting, must return a serialization of the collection of media queries. Setting the mediaText
attribute must run these steps:
The item(index)
method must return a serialization of the media query in the collection of media queries given by index, or null, if index is greater than or equal to the number of media queries in the collection of media queries.
The length
attribute must return the number of media queries in the collection of media queries.
The appendMedium(medium)
method must run these steps:
The deleteMedium(medium)
method must run these steps:
NotFoundError
exception.Selectors are defined in the Selectors specification. This section mainly defines how to serialize them.
5.1. Parsing SelectorsTo parse a group of selectors means to parse the value using the selectors_group
production defined in the Selectors specification and return either a group of selectors if parsing did not fail or null if parsing did fail.
To serialize a group of selectors serialize each selector in the group of selectors and then serialize a comma-separated list of these serializations.
To serialize a selector let s be the empty string, run the steps below for each part of the chain of the selector, and finally return s:
>
", "+
", "~
", ">>
", "||
", as appropriate, followed by another single SPACE (U+0020) if the combinator was not whitespace, to s.::
" followed by the name of the pseudo-element, to s.To serialize a simple selector let s be the empty string, run the steps below, and finally return s:
|
" (U+007C) to s.|
" (U+007C) to s.*
" (U+002A) to s.[
" (U+005B) to s.|
" (U+007C) to s.=
", "~=
", "|=
", "^=
", "$=
", or "*=
" as appropriate (depending on the type of attribute selector), followed by the serialization of the attribute value as a string, to s. i
" (U+0020 U+0069) to s.]
" (U+005D) to s..
" (U+002E), followed by the serialization of the class name as an identifier to s.
#
" (U+0023), followed by the serialization of the ID as an identifier to s.
:
" (U+003A), followed by the name of the pseudo-class, to s.
Otherwise, append ":
" (U+003A), followed by the name of the pseudo-class, followed by "(
" (U+0028), followed by the value of the pseudo-class argument(s) determined as per below, followed by ")
" (U+0029), to s.
:lang()
:nth-child()
:nth-last-child()
:nth-of-type()
:nth-last-of-type()
:not()
A CSS style sheet is an abstract concept that represents a style sheet as defined by the CSS specification. In the CSSOM a CSS style sheet is represented as a CSSStyleSheet
object.
CSSStyleSheet(options)
CSSStyleSheet
CSSStyleSheetInit
options, run these steps:
CSSStyleSheet
object sheet.baseURL
attribute value from options.media
attribute of options is a string, create a MediaList object from the string and assign it as sheet’s media. Otherwise, serialize a media query list from the attribute and then create a MediaList object from the resulting string and set it as sheet’s media.disabled
attribute of options is true, set sheet’s disabled flag.A CSS style sheet has a number of associated state items:
text/css
".
MediaList
object associated with the CSS style sheet.
If this property is specified to a string, the media must be set to the return value of invoking create a MediaList
object steps for that string.
If this property is specified to an attribute of the owner node, the media must be set to the return value of invoking create a MediaList
object steps for the value of that attribute. Whenever the attribute is set, changed or removed, the media’s mediaText
attribute must be set to the new value of the attribute, or to null if the attribute is absent.
Note: Changing the media’s mediaText
attribute does not change the corresponding attribute on the owner node.
Note: The owner node of a CSS style sheet, if non-null, is the node whose associated CSS style sheet is the CSS style sheet in question, when the CSS style sheet is added.
In the following, the
titleis non-empty for the first style sheet, but is empty for the second and third style sheets.
<style title="papaya whip"> body { background: #ffefd5; } </style>
<style title=""> body { background: orange; } </style>
<style> body { background: brown; } </style>
If this property is specified to an attribute of the owner node, the title must be set to the value of that attribute. Whenever the attribute is set, changed or removed, the title must be set to the new value of the attribute, or to the empty string if the attribute is absent.
Note: HTML only specifies title to be an attribute of the owner node if the node is in in a document tree.
The following
CSS style sheetshave their
alternate flagset:
<?xml-stylesheet alternate="yes" title="x" href="data:text/css,…"?>
<link rel="alternate stylesheet" title="x" href="data:text/css,…">
Note: Even when unset it does not necessarily mean that the CSS style sheet is actually used for rendering.
Document
a constructed stylesheet is associated with. Null by default. Only non-null for stylesheets that have constructed flag set.
StyleSheet
Interface
The StyleSheet
interface represents an abstract, base style sheet.
[Exposed=Window]
interface StyleSheet
{
readonly attribute CSSOMString type;
readonly attribute USVString? href;
readonly attribute (Element or ProcessingInstruction)? ownerNode;
readonly attribute CSSStyleSheet? parentStyleSheet;
readonly attribute DOMString? title;
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
attribute boolean disabled;
};
The type
attribute must return the type.
The href
attribute must return the location.
The ownerNode
attribute must return the owner node.
The parentStyleSheet
attribute must return the parent CSS style sheet.
The title
attribute must return the title or null if title is the empty string.
The media
attribute must return the media.
The disabled
attribute, on getting, must return true if the disabled flag is set, or false otherwise. On setting, the disabled
attribute must set the disabled flag if the new value is true, or unset the disabled flag otherwise.
CSSStyleSheet
Interface
The CSSStyleSheet
interface represents a CSS style sheet.
[Exposed=Window] interfaceCSSStyleSheet
: StyleSheet { constructor(optional CSSStyleSheetInitoptions
= {}); readonly attribute CSSRule? ownerRule; [SameObject] readonly attribute CSSRuleList cssRules; unsigned long insertRule(CSSOMStringrule
, optional unsigned longindex
= 0); undefined deleteRule(unsigned longindex
); Promise<CSSStyleSheet> replace(USVStringtext
); undefined replaceSync(USVStringtext
); }; dictionaryCSSStyleSheetInit
{ DOMStringbaseURL
= null; (MediaList or DOMString)media
= ""; booleandisabled
= false; };
The ownerRule
attribute must return the owner CSS rule. If a value other than null is ever returned, then that same value must always be returned on each get access.
The cssRules
attribute must follow these steps:
SecurityError
exception.CSSRuleList
object representing the CSS rules.
Note: Even though the returned CSSRuleList
object is read-only (from the perspective of client-authored script), it can nevertheless change over time due to its liveness status. For example, invoking the insertRule()
or deleteRule()
methods can result in mutations reflected in the returned object.
The insertRule(rule, index)
method must run the following steps:
SecurityError
exception.NotAllowedError
DOMException
.SyntaxError
DOMException
.SyntaxError
DOMException
.The deleteRule(index)
method must run the following steps:
SecurityError
exception.NotAllowedError
DOMException
.The replace(text)
method must run the following steps:
NotAllowedError
DOMException
and return promise.The replaceSync(text)
method must run the steps to synchronously replace the rules of a CSSStyleSheet on this CSSStyleSheet
given text.
To synchronously replace the rules of a CSSStyleSheet on sheet given text, run these steps:
NotAllowedError
DOMException
.Note: These members are required for compatibility with existing sites.
partial interface CSSStyleSheet { [SameObject] readonly attribute CSSRuleList rules; long addRule(optional DOMStringselector
= "undefined", optional DOMStringstyle
= "undefined", optional unsigned longindex
); undefined removeRule(optional unsigned longindex
= 0); };
The rules
attribute must follow the same steps as cssRules
, and return the same object cssRules
would return.
The removeRule(index)
method must run the same steps as deleteRule()
.
The addRule(selector, block, optionalIndex)
method must run the following steps:
" { "
to rule."}"
to ruleinsertRule()
, with rule and index as arguments.-1
.Authors should not use these members and should instead use and teach the standard CSSStyleSheet
interface defined earlier, which is consistent with CSSGroupingRule
.
Below various new concepts are defined that are associated with each DocumentOrShadowRoot
object.
Each DocumentOrShadowRoot
has an associated list of zero or more CSS style sheets, named the document or shadow root CSS style sheets. This is an ordered list that contains:
Link
headers, in header orderDocumentOrShadowRoot
, in tree orderEach DocumentOrShadowRoot
has an associated list of zero or more CSS style sheets, named the final CSS style sheets. This is an ordered list that contains:
DocumentOrShadowRoot
’s adoptedStyleSheets
' backing list, in array order.To create a CSS style sheet, run these steps:
If the origin-clean flag is unset, this can expose information from the user’s intranet.
To add a CSS style sheet, run these steps:
If the CSS style sheet’s owner node contributes a script-blocking style sheet, then user agents must append the owner node to its node document’s script-blocking style sheet set.
The remainder of these steps deal with the disabled flag.
To remove a CSS style sheet, run these steps:
A persistent CSS style sheet is a CSS style sheet from the document or shadow root CSS style sheets whose title is the empty string and whose alternate flag is unset.
A CSS style sheet set is an ordered collection of one or more CSS style sheets from the document or shadow root CSS style sheets which have an identical title that is not the empty string.
A CSS style sheet set name is the title the CSS style sheet set has in common.
An enabled CSS style sheet set is a CSS style sheet set of which each CSS style sheet has its disabled flag unset.
To enable a CSS style sheet set with name name, run these steps:
To select a CSS style sheet set with name name, run these steps:
A last CSS style sheet set name is a concept to determine what CSS style sheet set was last selected. Initially its value is null.
A preferred CSS style sheet set name is a concept to determine which CSS style sheets need to have their disabled flag unset. Initially its value is the empty string.
To change the preferred CSS style sheet set name with name name, run these steps:
The HTTP Default-Style header can be used to set the preferred CSS style sheet set name influencing which CSS style sheet set is (initially) the enabled CSS style sheet set.
For each HTTP Default-Style header, in header order, the user agent must change the preferred CSS style sheet set name with name being the value of the header.
6.2.2. TheStyleSheetList
Interface
The StyleSheetList
interface represents an ordered collection of CSS style sheets.
[Exposed=Window] interfaceStyleSheetList
{ getter CSSStyleSheet? item(unsigned longindex
); readonly attribute unsigned long length; };
The object’s supported property indices are the numbers in the range zero to one less than the number of CSS style sheets represented by the collection. If there are no such CSS style sheets, then there are no supported property indices.
The item(index)
method must return the indexth CSS style sheet in the collection. If there is no indexth object in the collection, then the method must return null.
The length
attribute must return the number of CSS style sheets represented by the collection.
DocumentOrShadowRoot
Interface Mixin
partial interface mixin DocumentOrShadowRoot { [SameObject] readonly attribute StyleSheetList styleSheets; attribute ObservableArray<CSSStyleSheet> adoptedStyleSheets; };
The styleSheets
attribute must return a StyleSheetList
collection representing the document or shadow root CSS style sheets.
The set an indexed value algorithm for adoptedStyleSheets
, given value and index, is the following:
DocumentOrShadowRoot
’s node document, throw a "NotAllowedError
" DOMException
.This section defines the interface an owner node of a CSS style sheet has to implement and defines the requirements for xml-stylesheet processing instructions and HTTP Link
headers when the link relation type is an ASCII case-insensitive match for "stylesheet
".
To
fetch a CSS style sheetwith parsed URL
parsed URL, referrer
referrer, document
document, optionally a set of parameters
parameters(used as input to creating a
request), and an algorithm for handling the response result
processTheResponsethat takes a response, follow these steps:
text/css
.LinkStyle
Interface
The associated CSS style sheet of a node is the CSS style sheet in the list of document or shadow root CSS style sheets of which the owner node is said node. This node must also implement the LinkStyle
interface.
interface mixin LinkStyle
{
readonly attribute CSSStyleSheet? sheet;
};
The sheet
attribute must return the associated CSS style sheet for the node or null if there is no associated CSS style sheet.
In the following fragment, the first
style
element has a
sheet
attribute that returns a
StyleSheet
object representing the style sheet, but for the second
style
element, the
sheet
attribute returns null, assuming the user agent supports CSS (
text/css
), but does not support the (hypothetical) ExampleSheets (
text/example-sheets
).
<style type="text/css"> body { background:lime } </style>
<style type="text/example-sheets"> $(body).background := lime </style>
Note: Whether or not the node refers to a style sheet is defined by the specification that defines the semantics of said node.
6.3.3. Requirements on specificationsSpecifications introducing new ways of associating style sheets through the DOM should define which nodes implement the LinkStyle
interface. When doing so, they must also define when a CSS style sheet is created.
ProcessingInstruction includes LinkStyle;
The prolog refers to nodes that are children of the Document
and are not following the Element
child of the Document
, if any.
When a
ProcessingInstruction
node node
becomes part of the
prolog, is no longer part of the
prolog, or has its
datachanged, these steps must be run:
href
pseudo-attribute, then return.title
pseudo-attribute or the empty string if the title
pseudo-attribute is not specified.alternate
pseudo-attribute whose value is a case-sensitive match for "yes
" and title is the empty string, then return.type
pseudo-attribute whose value is not a supported styling language the user agent may return.href
pseudo-attribute.media
pseudo-attribute if any, or the empty string otherwise.
alternate
pseudo-attribute value is a case-sensitive match for "yes
", or unset otherwise.
The CSS environment encoding is the result of running the following steps:
charset
pseudo-attribute, get an encoding from that pseudo-attribute’s value. If that succeeds, return the resulting encoding and abort these steps.For each HTTP Link
header of which one of the link relation types is an ASCII case-insensitive match for "stylesheet
" these steps must be run:
title
parameters. If there are no such parameters it is the empty string.alternate
" and title is the empty string, then return.What if the HTML parser hasn’t decided on quirks/non-quirks yet?
media
parameter.
Link
header is an ASCII case-insensitive match for "alternate
", or false otherwise.
A style sheet referenced by a HTTP Link
header using the rules in this section is said to be a style sheet that is blocking scripts if the style sheet was enabled when created, and the user agent hasn’t given up on that particular style sheet yet. A user agent may give up on such a style sheet at any time.
A CSS rule is an abstract concept that denotes a rule as defined by the CSS specification. A CSS rule is represented as an object that implements a subclass of the CSSRule
interface, and which has the following associated state items:
In addition to the above state, each CSS rule may be associated with other state in accordance with its type.
To parse a CSS rule from a string string, run the following steps:
To serialize a CSS rule, perform one of the following in accordance with the CSS rule’s type:
CSSStyleRule
{
", i.e., a single SPACE (U+0020), followed by LEFT CURLY BRACKET (U+007B).cssRules
list, or null if there are no such rules.CSSImportRule
@import
" followed by a single SPACE (U+0020).;
", i.e., SEMICOLON (U+003B).@import url("import.css");
@import url("print.css") print;
CSSMediaRule
@media
", followed by a single SPACE (U+0020).cssRules
list, filtering out empty strings, indenting each item with two spaces, all joined with newline.CSSFontFaceRule
@font-face {
", followed by a single SPACE (U+0020).font-family:
", followed by a single SPACE (U+0020).;
", i.e., SEMICOLON (U+003B).src:
", followed by a single SPACE (U+0020).;
", i.e., SEMICOLON (U+003B).unicode-range:
", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'unicode-range'>, followed by the string ";
", i.e., SEMICOLON (U+003B).font-variant:
", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'font-variant'>, followed by the string ";
", i.e., SEMICOLON (U+003B).font-feature-settings:
", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'font-feature-settings'>, followed by the string ";
", i.e., SEMICOLON (U+003B).font-stretch:
", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'font-stretch'>, followed by the string ";
", i.e., SEMICOLON (U+003B).font-weight:
", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'font-weight'>, followed by the string ";
", i.e., SEMICOLON (U+003B).font-style:
", followed by a single SPACE (U+0020), followed by the result of performing serialize a <'font-style'>, followed by the string ";
", i.e., SEMICOLON (U+003B). Need to define how the CSSFontFaceRule
descriptors' values are serialized.
CSSPageRule
Need to define how CSSPageRule
is serialized.
CSSNamespaceRule
@namespace
", followed by a single SPACE (U+0020), followed by the serialization as an identifier of the prefix
attribute (if any), followed by a single SPACE (U+0020) if there is a prefix, followed by the serialization as URL of the namespaceURI
attribute, followed the character ";
" (U+003B).
CSSKeyframesRule
@keyframes
", followed by a single SPACE (U+0020).name
attribute. If the attribute is a CSS wide keyword, or the value default, or the value none, then it is serialized as a string. Otherwise, it is serialized as an identifier. {
", i.e., a single SPACE (U+0020), followed by LEFT CURLY BRACKET (U+007B), followed by a single SPACE (U+0020).cssRules
list, separated by a newline and indented by two spaces.CSSKeyframeRule
keyText
. {
", i.e., a single SPACE (U+0020), followed by LEFT CURLY BRACKET (U+007B), followed by a single SPACE (U+0020).
", i.e., a single SPACE (U+0020).}
", RIGHT CURLY BRACKET (U+007D).The "indented by two spaces" bit matches browsers, but needs work, see #5494
To insert a CSS rule rule in a CSS rule list list at index index, with a flag nested, follow these steps:
IndexSizeError
exception.SyntaxError
exception.SyntaxError
exception.HierarchyRequestError
exception. [CSS21]
Note: For example, a CSS style sheet cannot contain an @import
at-rule after a style rule.
@namespace
at-rule, and list contains anything other than @import
at-rules, and @namespace
at-rules, throw an InvalidStateError
exception.To remove a CSS rule from a CSS rule list list at index index, follow these steps:
IndexSizeError
exception.@namespace
at-rule, and list contains anything other than @import
at-rules, and @namespace
at-rules, throw an InvalidStateError
exception.CSSRuleList
Interface
The CSSRuleList
interface represents an ordered collection of CSS rules.
[Exposed=Window] interfaceCSSRuleList
{ getter CSSRule? item(unsigned longindex
); readonly attribute unsigned long length; };
The object’s supported property indices are the numbers in the range zero to one less than the number of CSSRule
objects represented by the collection. If there are no such CSSRule
objects, then there are no supported property indices.
The item(index)
method must return the indexth CSSRule
object in the collection. If there is no indexth object in the collection, then the method must return null.
The length
attribute must return the number of CSSRule
objects represented by the collection.
CSSRule
Interface
The CSSRule
interface represents an abstract, base CSS rule. Each distinct CSS rule type is represented by a distinct interface that inherits from this interface.
[Exposed=Window] interfaceCSSRule
{ attribute CSSOMString cssText; readonly attribute CSSRule? parentRule; readonly attribute CSSStyleSheet? parentStyleSheet; // the following attribute and constants are historical readonly attribute unsigned short type; const unsigned shortSTYLE_RULE
= 1; const unsigned shortCHARSET_RULE
= 2; const unsigned shortIMPORT_RULE
= 3; const unsigned shortMEDIA_RULE
= 4; const unsigned shortFONT_FACE_RULE
= 5; const unsigned shortPAGE_RULE
= 6; const unsigned shortMARGIN_RULE
= 9; const unsigned shortNAMESPACE_RULE
= 10; };
The cssText
attribute must return a serialization of the CSS rule. On setting the cssText
attribute must do nothing.
The parentRule
attribute must return the parent CSS rule.
Note: For example, @media
can enclose a rule, in which case parentRule
would be non-null; in cases where there is no enclosing rule, parentRule
will be null.
The parentStyleSheet
attribute must return the parent CSS style sheet.
Note: The only circumstance where null is returned when a rule has been removed.
Note: Removing a Node
that implements the LinkStyle
interface from a Document
instance does not (by itself) cause the CSSStyleSheet
referenced by a CSSRule
to be unreachable.
The type
attribute is deprecated. It must return an integer, as follows:
CSSStyleRule
CSSImportRule
CSSMediaRule
CSSFontFaceRule
CSSPageRule
CSSKeyframesRule
CSSKeyframeRule
CSSMarginRule
CSSNamespaceRule
CSSCounterStyleRule
CSSSupportsRule
CSSFontFeatureValuesRule
Note: The practice of using an integer enumeration and several constants to identify the integers is a legacy design practice that is no longer used in Web APIs. Instead, to tell what type of rule a given object is, it is recommended to check rule . constructor . name
, which will return a string like "CSSStyleRule"
. This enumeration is thus frozen in its current state, and no new new values will be added to reflect additional at-rules; all at-rules beyond the ones listed above will return 0.
CSSStyleRule
Interface
The CSSStyleRule
interface represents a style rule.
[Exposed=Window]
interface CSSStyleRule
: CSSGroupingRule {
attribute CSSOMString selectorText;
[SameObject, PutForwards=cssText] readonly attribute CSSStyleProperties style;
};
The selectorText
attribute, on getting, must return the result of serializing the rule’s associated selector list. On setting the selectorText
attribute these steps must be run:
The style
attribute must return a CSSStyleProperties
object for the style rule, with the following properties:
The specified order for declarations is the same as specified, but with shorthand properties expanded into their longhand properties, in canonical order. If a property is specified more than once (after shorthand expansion), only the one with greatest cascading order must be represented, at the same relative position as it was specified. [CSS3CASCADE]
6.4.4. TheCSSImportRule
Interface
The CSSImportRule
interface represents an @import
at-rule.
[Exposed=Window]
interface CSSImportRule
: CSSRule {
readonly attribute USVString href;
[SameObject, PutForwards=mediaText] readonly attribute MediaList media;
[SameObject] readonly attribute CSSStyleSheet? styleSheet;
readonly attribute CSSOMString? layerName;
readonly attribute CSSOMString? supportsText;
};
The href
attribute must return the URL specified by the @import
at-rule.
Note: To get the resolved URL use the href
attribute of the associated CSS style sheet.
The media
attribute must return the value of the media
attribute of the associated CSS style sheet.
The styleSheet
attribute must return the associated CSS style sheet, if any, or null otherwise.
The layerName
attribute must return the layer name declared in the at-rule itself, or an empty string if the layer is anonymous, or null if the at-rule does not declare a layer.
The supportsText
attribute must return the <supports-condition> declared in the at-rule itself, or null if the at-rule does not declare a supports condition.
Note: An @import
at-rule might not have an associated CSS style sheet (e.g., if it has a non-matching supports()
condition).
CSSGroupingRule
Interface
The CSSGroupingRule
interface represents an at-rule that contains other rules nested inside itself.
[Exposed=Window] interfaceCSSGroupingRule
: CSSRule { [SameObject] readonly attribute CSSRuleList cssRules; unsigned long insertRule(CSSOMStringrule
, optional unsigned longindex
= 0); undefined deleteRule(unsigned longindex
); };
The cssRules
attribute must return a CSSRuleList
object for the child CSS rules.
The insertRule(rule, index)
method must return the result of invoking insert a CSS rule rule into the child CSS rules at index, with the nested flag set.
The deleteRule(index)
method must remove a CSS rule from the child CSS rules at index.
CSSMediaRule
Interface
The CSSMediaRule
interface is defined in CSS Conditional Rules. [CSS3-CONDITIONAL]
The CSSPageRule
interface represents an @page
at-rule.
Need to define the rules for parse a list of CSS page selectors and serialize a list of CSS page selectors.
[Exposed=Window] interfaceCSSPageDescriptors
: CSSStyleDeclaration { attribute [LegacyNullToEmptyString] CSSOMStringmargin
; attribute [LegacyNullToEmptyString] CSSOMStringmarginTop
; attribute [LegacyNullToEmptyString] CSSOMStringmarginRight
; attribute [LegacyNullToEmptyString] CSSOMStringmarginBottom
; attribute [LegacyNullToEmptyString] CSSOMStringmarginLeft
; attribute [LegacyNullToEmptyString] CSSOMStringmargin-top
; attribute [LegacyNullToEmptyString] CSSOMStringmargin-right
; attribute [LegacyNullToEmptyString] CSSOMStringmargin-bottom
; attribute [LegacyNullToEmptyString] CSSOMStringmargin-left
; attribute [LegacyNullToEmptyString] CSSOMStringsize
; attribute [LegacyNullToEmptyString] CSSOMStringpageOrientation
; attribute [LegacyNullToEmptyString] CSSOMStringpage-orientation
; attribute [LegacyNullToEmptyString] CSSOMStringmarks
; attribute [LegacyNullToEmptyString] CSSOMStringbleed
; }; [Exposed=Window] interface : CSSGroupingRule { attribute CSSOMString selectorText; [SameObject, PutForwards=cssText] readonly attribute CSSPageDescriptors style; };
The attribute, on getting, must return the result of serializing the associated selector list. On setting the selectorText
attribute these steps must be run:
The attribute must return a CSSPageDescriptors
object for the @page
at-rule, with the following properties:
CSSMarginRule
Interface
The CSSMarginRule
interface represents a margin at-rule (e.g. @top-left
) in an @page
at-rule. [CSS3PAGE]
[Exposed=Window]
interface CSSMarginRule
: CSSRule {
readonly attribute CSSOMString name;
[SameObject, PutForwards=cssText] readonly attribute CSSMarginDescriptors style;
};
The name
attribute must return the name of the margin at-rule. The @
character is not included in the name. [CSS3SYN]
The style
attribute must return a CSSMarginDescriptors
object for the margin at-rule, with the following properties:
CSSNamespaceRule
Interface
The CSSNamespaceRule
interface represents an @namespace
at-rule.
[Exposed=Window]
interface CSSNamespaceRule
: CSSRule {
readonly attribute CSSOMString namespaceURI;
readonly attribute CSSOMString prefix;
};
The namespaceURI
attribute must return the namespace of the @namespace
at-rule.
The prefix
attribute must return the prefix of the @namespace
at-rule or the empty string if there is no prefix.
A CSS declaration is an abstract concept that is not exposed as an object in the DOM. A CSS declaration has the following associated properties:
A CSS declaration block is an ordered collection of CSS properties with their associated values, also named CSS declarations. In the DOM a CSS declaration block is a CSSStyleDeclaration
object. A CSS declaration block has the following associated properties:
Element
that the CSS declaration block is associated with, if any, or null otherwise.
style
attribute.
To parse a CSS declaration block from a string string, follow these steps:
To serialize a CSS declaration with property name property, value value and optionally an important flag set, follow these steps:
:
" (U+003A U+0020) to s. !important
" (U+0020 U+0021 U+0069 U+006D U+0070 U+006F U+0072 U+0074 U+0061 U+006E U+0074) to s.;
" (U+003B) to s.To serialize a CSS declaration block declaration block means to run the steps below:
" (U+0020).Note: The serialization of an empty CSS declaration block is the empty string.
Note: The serialization of a non-empty CSS declaration block does not include any surrounding whitespace, i.e., no whitespace appears before the first property name and no whitespace appears after the final semicolon delimiter that follows the last property value.
A CSS declaration block has these attribute change steps for its owner node with localName, value, and namespace:
style
", or namespace is not null, then return.When a CSS declaration block object is created, then:
style
", and owner node.To update style attribute for declaration block means to run the steps below:
style
" and the result of serializing declaration block.The preferred order of a list of shorthand properties shorthands is as follows:
-
" (U+002D) last in the list, retaining their relative order.-
" (U+002D) but do not begin with "-webkit-
" last in the list, retaining their relative order.CSSStyleDeclaration
Interface
The CSSStyleDeclaration
interface represents a CSS declaration block, including its underlying state, where this underlying state depends upon the source of the CSSStyleDeclaration
instance.
[Exposed=Window] interfaceCSSStyleDeclaration
{ [CEReactions] attribute CSSOMString cssText; readonly attribute unsigned long length; getter CSSOMString item(unsigned longindex
); CSSOMString getPropertyValue(CSSOMStringproperty
); CSSOMString getPropertyPriority(CSSOMStringproperty
); [CEReactions] undefined setProperty(CSSOMStringproperty
, [LegacyNullToEmptyString] CSSOMStringvalue
, optional [LegacyNullToEmptyString] CSSOMStringpriority
= ""); [CEReactions] CSSOMString removeProperty(CSSOMStringproperty
); readonly attribute CSSRule? parentRule; }; [Exposed=Window] interfaceCSSStyleProperties
: CSSStyleDeclaration { [CEReactions] attribute [LegacyNullToEmptyString] CSSOMString cssFloat; };
The object’s supported property indices are the numbers in the range zero to one less than the number of CSS declarations in the declarations. If there are no such CSS declarations, then there are no supported property indices.
Getting the cssText
attribute must run these steps:
If the computed flag is set, then return the empty string.
Return the result of serializing the declarations.
Setting the cssText
attribute must run these steps:
NoModificationAllowedError
exception.The length
attribute must return the number of CSS declarations in the declarations.
The item(index)
method must return the property name of the CSS declaration at position index.
The getPropertyValue(property)
method must run these steps:
The getPropertyPriority(property)
method must run these steps:
getPropertyPriority()
with longhand as argument to list.important
", then return the string "important
".important
".E.g. for
background-color:lime !IMPORTANT
the return value would be "
important
".
The setProperty(property, value, priority)
method must run these steps:
NoModificationAllowedError
exception.removeProperty()
with property as argument and return.important
", then return.Note: value can not include "!important
".
To set a CSS declaration property with a value component value list and optionally with an important flag set, in a list of declarations declarations, the user agent must ensure the following constraints hold after its steps:
Should we add something like "Any observable side effect must not be made outside declarations"? The current constraints sound like a hole for undefined behavior.
Note: The steps of set a CSS declaration are not defined in this level of CSSOM. User agents may use different algorithms as long as the constraints above hold.
The simplest way to conform with the constraints would be to always remove any existing declaration matching
property, and append the new declaration to the end. But based on implementation feedback, this approach would likely regress performance.
Another possible algorithm is:
The removeProperty(property)
method must run these steps:
NoModificationAllowedError
exception.getPropertyValue()
with property as argument.The parentRule
attribute must return the parent CSS rule.
The cssFloat
attribute, on getting, must return the result of invoking getPropertyValue()
with float
as argument. On setting, the attribute must invoke setProperty()
with float
as first argument, as second argument the given value, and no third argument. Any exceptions thrown must be re-thrown.
For each CSS property property that is a supported CSS property, the following partial interface applies where camel-cased attribute
is obtained by running the CSS property to IDL attribute algorithm for property.
The camel-cased attribute attribute, on getting, must return the result of invoking getPropertyValue()
with the argument being the result of running the IDL attribute to CSS property algorithm for camel-cased attribute.
Setting the camel-cased attribute attribute must invoke setProperty()
with the first argument being the result of running the IDL attribute to CSS property algorithm for camel-cased attribute, as second argument the given value, and no third argument. Any exceptions thrown must be re-thrown.
For example, for the
font-sizeproperty there would be a
fontSize
IDL attribute.
For each CSS property property that is a supported CSS property and that begins with the string -webkit-
, the following partial interface applies where webkit-cased attribute is obtained by running the CSS property to IDL attribute algorithm for property, with the lowercase first flag set.
The webkit-cased attribute
attribute, on getting, must return the result of invoking getPropertyValue()
with the argument being the result of running the IDL attribute to CSS property algorithm for webkit-cased attribute, with the dash prefix flag set.
Setting the webkit-cased attribute attribute must invoke setProperty()
with the first argument being the result of running the IDL attribute to CSS property algorithm for webkit-cased attribute, with the dash prefix flag set, as second argument the given value, and no third argument. Any exceptions thrown must be re-thrown.
For example, if the user agent supports the
-webkit-transformproperty, there would be a
webkitTransform
IDL attribute. There would also be a
WebkitTransform
IDL attribute because of the rules for camel-cased attributes.
For each CSS property property that is a supported CSS property, except for properties that have no "-
" (U+002D) in the property name, the following partial interface applies where dashed attribute is property.
The dashed attribute
attribute, on getting, must return the result of invoking getPropertyValue()
with the argument being dashed attribute.
Setting the dashed attribute attribute must invoke setProperty()
with the first argument being dashed attribute, as second argument the given value, and no third argument. Any exceptions thrown must be re-thrown.
For example, for the
font-sizeproperty there would be a
font-size
IDL attribute. In JavaScript, the property can be accessed as follows, assuming
elementis an
HTML element:
element.style['font-size'];
The CSS property to IDL attribute algorithm for property, optionally with a lowercase first flag set, is as follows:
-
" (U+002D), let uppercase next be set.The IDL attribute to CSS property algorithm for attribute, optionally with a dash prefix flag set, is as follows:
-
" (U+002D) to output.-
" (U+002D) followed by c converted to ASCII lowercase to output.To parse a CSS value value for a given property means to follow these steps:
Note: "!important
" declarations are not part of the property value space and will therefore cause parse a CSS value to return null.
To serialize a CSS value of a CSS declaration declaration or a list of longhand CSS declarations list, follow these rules:
If this algorithm is invoked with a list list:
Let shorthand be the first shorthand property, in preferred order, that exactly maps to all of the longhand properties in list.
If there is no such shorthand or shorthand cannot exactly represent the values of all the properties in list, return the empty string.
Otherwise, serialize a CSS value from a hypothetical declaration of the property shorthand with its value representing the combined values of the declarations in list.
Represent the value of the declaration as a list of CSS component values components that, when parsed according to the property’s grammar, would represent that value. Additionally, unless otherwise specified:
If certain component values can appear in any order without changing the meaning of the value (a pattern typically represented by a double bar || in the value syntax), reorder the component values to use the canonical order of component values as given in the property definition table.
If component values can be omitted or replaced with a shorter representation without changing the meaning of the value, omit/replace them.
If either of the above syntactic translations would be less backwards-compatible, do not perform them.
Note: The rules described here outline the general principles of serialization. For legacy reasons, some properties serialize in a different manner, which is intentionally undefined here due to lack of resources. Please consult that property’s specification and/or your local reverse-engineer for details.
Remove any <whitespace-token>s from components.
Replace each component value in components with the result of invoking serialize a CSS component value.
Join the items of components into a single string, inserting " " (U+0020 SPACE) between each pair of items unless the second item is a "," (U+002C COMMA) Return the result.
To serialize a CSS component value depends on the component, as follows:
Probably should distinguish between declared and computed / resolved values.
If <color> is a component of a computed value, see CSS Color 4 § 15. Serializing <color> Values.
If <color> is a component of a declared value, then for sRGB values, see CSS Color 4 § 14.1 Resolving sRGB values. For other color functions, see CSS Color 4 § 14. Resolving <color> Values.
counters(
" to s.counter(
" to s.)
" (U+0029) to s.Probably should distinguish between declared and computed / resolved values.
-
" (U+002D) if it is negative.
Probably should distinguish between declared and computed / resolved values.
.
" to separate decimals (if any), rounding the value if necessary to not produce more than 6 decimals, preceded by "-
" (U+002D) if it is negative.
Note: scientific notation is not used.
%
" (U+0025).
dppx
".
/
", followed by the denominator serialized as per <number>.
rect(
".)
" (U+0029) to s.s
".
This should differentiate declared and computed <url> values, see #3195.
<absolute-size>, <border-width>, <border-style>, <bottom>, <generic-family>, <generic-voice>, <left>, <margin-width>, <padding-width>, <relative-size>, <right>, and <top>, are considered macros by this specification. They all represent instances of components outlined above.
One idea is that we can remove this section somewhere in the CSS3/CSS4 timeline by moving the above definitions to the drafts that define the CSS components.
6.7.2.1. ExamplesHere are some examples of before and after results on declared values. The before column could be what the author wrote in a style sheet, while the after column shows what querying the DOM would return.
Before Afterbackground: none
background: rgba(0, 0, 0, 0)
outline: none
outline: invert
border: none
border: medium
list-style: none
list-style: disc
margin: 0 1px 1px 1px
margin: 0px 1px 1px
azimuth: behind left
azimuth: 220deg
font-family: a, 'b"', serif
font-family: "a", "b\"", serif
content: url('h)i') '\[\]'
content: url("h)i") "[]"
azimuth: leftwards
azimuth: leftwards
color: rgb(18, 52, 86)
color: #123456
color: rgba(000001, 0, 0, 1)
color: #000000
Some of these need to be updated per the new rules.
7. DOM Access to CSS Declaration Blocks 7.1. TheElementCSSInlineStyle
Mixin
The ElementCSSInlineStyle
mixin provides access to inline style properties of an element.
interface mixin ElementCSSInlineStyle
{
[SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
};
The style
attribute must return a CSS declaration block object whose readonly flag is unset, whose parent CSS rule is null, and whose owner node is this.
If the user agent supports HTML, the following IDL applies: [HTML]
HTMLElement includes ElementCSSInlineStyle;
If the user agent supports SVG, the following IDL applies: [SVG11]
SVGElement includes ElementCSSInlineStyle;
If the user agent supports MathML, the following IDL applies: [MathML-Core]
MathMLElement includes ElementCSSInlineStyle;7.2. Extensions to the
Window
Interface
partial interface Window { [NewObject] CSSStyleDeclaration getComputedStyle(Elementelt
, optional CSSOMString?pseudoElt
); };
The getComputedStyle(elt, pseudoElt)
method must run these steps:
Note: CSS2 pseudo-elements should match both the double and single-colon versions. That is, both :before
and ::before
should match above.
There are UAs that handle shorthands, and all UAs handle shorthands that used to be longhands like overflow, see #2529.
Order of custom properties is currently undefined, see #4947.
CSSStyleProperties
object with the following properties:
The getComputedStyle()
method exposes information from CSS style sheets with the origin-clean flag unset.
Should getComputedStyle() provide a useful serialization? See #1033
8. Utility APIs 8.1. TheCSS.escape()
Method
The CSS
namespace holds useful CSS-related functions that do not belong elsewhere.
[Exposed=Window] namespaceCSS
{ CSSOMString escape(CSSOMStringident
); };
This was previously specified as an IDL interface that only held static methods. Switching to an IDL namespace is *nearly* identical, so it’s expected that there won’t be any compat concerns. If any are discovered, please report so we can consider reverting this change.
The escape(ident)
operation must return the result of invoking serialize an identifier of ident.
For example, to serialize a string for use as part of a selector, the
escape()
method can be used:
var element = document.querySelector('#' + CSS.escape(id) + ' > img');
The
escape()
method can also be used for escaping strings, although it escapes characters that don’t strictly need to be escaped:
var element = document.querySelector('a[href="#' + CSS.escape(fragment) + '"]');
Specifications that define operations on the CSS
namespace and want to store some state should store the state on the current global object’s associated Document
.
getComputedStyle()
was historically defined to return the "computed value" of an element or pseudo-element. However, the concept of "computed value" changed between revisions of CSS while the implementation of getComputedStyle()
had to remain the same for compatibility with deployed scripts. To address this issue this specification introduces the concept of a resolved value.
The resolved value for a given longhand property can be determined as follows:
This section describes a header field for registration in the Permanent Message Header Field Registry.
This section documents some of the changes between publications of this specification. This section is not exhaustive. Bug fixes and editorial changes are generally not listed.
11.1. Changes From 17 March 2016Serialization of <resolution> is changed.
[CEReactions]
IDL extended attributes are added.
Resolved value for logical properties are added.
MediaList.item
now returns serialization.
MediaList.item
does not serialize shorthand if importance differs.
Other specifications are allowed to specify resolved value.
index
argument in insertRule
is now optional.
href
attribute of Stylesheet
and CSSImportRule
now uses USVString
.
CSSOMString
is introduced.
Serialization of CSSMediaRule
and CSSFontFaceRule
is added.
Updating flag is added to CSS declaration block to avoid serialize-and-reparse on style attribute.
Serialization of a declaration value is now properly defined.
getComputedStyle
now returns the style rules of the node’s document.
A TypeError
is thrown when the pseudo-element passed to getComputedStyle
is unknown or ::slotted().
CSS
is switched from interface to namespace.
setPropertyValue
and setPropertyPriority
are removed from CSSStyleDeclaration
due to lack of interest from implementations.
The styleSheets
IDL attribute is moved from Document
to DocumentOrShadowRoot
.
LinkStyle.sheet now returns CSSStyleSheet
instead of StyleSheet
Deprecated CSSStyleSheet members are defined.
The CSSRule.type
attribute is deprecated.
Serialization of <ratio> is added.
CSSStyleDeclaration.cssText
now returns the empty string for computed style.
Custom properties are included in getComputedStyle
.
MathML IDL is introduced.
Serialization of CSSKeyframesRule
and CSSKeyframeRule
is added.
Serialization of media query is changed.
A shorthand is not serialized if there are longhands with other property group / mapping logic in between the longhands of that shorthand.
CSSStyleRule
serialization is aware of nesting now.
Constructable stylesheets is introduced.
API for alternative stylesheets is removed: selectedStyleSheetSet
, lastStyleSheetSet
, preferredStyleSheetSet
, styleSheetSets
, enableStyleSheetsForSet()
on Document
.
The pseudo()
method on Element
and the PseudoElement
interface is removed.
The cascadedStyle
, defaultStyle
, rawComputedStyle
and usedStyle
IDL attributes on Element
are removed.
The cssText
IDL attribute’s setter on CSSRule
is changed to do nothing.
IDL attributes of the form webkitFoo
(with lowercase w
) on CSSStyleDeclaration
are added.
CSSNamespaceRule
is changed back to readonly.
Handling of @charset
in insertRule()
is removed.
CSSCharsetRule
is removed again.
Serialization of identifiers and strings is changed.
Serialization of selectors now supports combinators ">>" and "||" and the "i" flag in attribute selectors.
Serialization of :lang() is changed.
setProperty()
on CSSStyleDeclaration
is changed.
CSSCharsetRule
is re-introduced.CSSGroupingRule
and CSSMarginRule
are introduced.CSSNamespaceRule
is now mutable.setProperty()
, getPropertyValue()
, et al.setPropertyValue
and setPropertyPriority
are added to CSSStyleDeclaration
.style
and media
attributes of various interfaces are annotated with the [PutForwards]
WebIDL extended attribute.pseudo()
method on Element
is introduced.PseudoElement
interface is introduced.cascadedStyle
, rawComputedStyle
and usedStyle
attributes on Element
and PseudoElement
are introduced.No new security considerations have been reported on this specification.
13. Privacy ConsiderationsNo new privacy considerations have been reported on this specification.
14. AcknowledgmentsThe editors would like to thank Alexey Feldgendler, Benjamin Poulain, Björn Höhrmann, Boris Zbasky, Brian Kardell, Chris Dumez, Christian Krebs, Daniel Glazman, David Baron, Domenic Denicola, Dominique Hazael-Massieux, fantasai, Hallvord R. M. Steen, Ian Hickson, John Daggett, Lachlan Hunt, Mike Sherov, Myles C. Maxfield, Morten Stenshorne, Ms2ger, Nazım Can Altınova, Øyvind Stenhaug, Peter Sloetjes, Philip Jägenstedt, Philip Taylor, Richard Gibson, Robert O’Callahan, Simon Sapin, Sjoerd Visscher, Sylvain Galineau, Tarquin Wilton-Jones, Xidorn Quan, and Zack Weinberg for contributing to this specification.
Additional thanks to Ian Hickson for writing the initial version of the alternative style sheets API and canonicalization (now serialization) rules for CSS values.
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:
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.
Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">
, like this: UAs MUST provide an accessible alternative.
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3