Sun, 31 Jan 2016 15:42:31 -0800
change //dev.w3.org/csswg/ urls to //drafts.csswg.org/
1 <pre class='metadata'>
2 Title: CSS Object Model (CSSOM)
3 ED: https://drafts.csswg.org/cssom/
4 TR: http://www.w3.org/TR/cssom/
5 Previous Version: http://www.w3.org/TR/2013/WD-cssom-20131205/
6 Previous Version: http://www.w3.org/TR/2011/WD-cssom-20110712/
7 Previous Version: http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/
8 Group: CSSWG
9 Status: ED
10 Work Status: Exploring
11 Shortname: cssom
12 Level: 1
13 Editor: Simon Pieters, Opera Software ASA http://www.opera.com, [email protected]
14 Editor: Daniel Glazman, Disruptive Innovations http://disruptive-innovations.com/, [email protected]
15 Former Editor: Glenn Adams, Cox Communications, Inc. http://www.cox.com, [email protected], http://www.w3.org/wiki/User:Gadams
16 Former Editor: Anne van Kesteren, Opera Software ASA http://www.opera.com, [email protected], https://annevankesteren.nl/
17 !Issues list: <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=CSS&component=CSSOM&resolution=---">Bugzilla</a> (<a href="https://www.w3.org/Bugs/Public/enter_bug.cgi?product=CSS&component=CSSOM">file a bug</a>)
18 Abstract: CSSOM defines APIs (including generic parsing and serialization rules) for Media Queries, Selectors, and of course CSS itself.
19 Ignored Terms: EmptyString, mediaText, cssText, InvalidCharacterError, SecurityError, SyntaxError, IndexSizeError, HierarchyRequestError, InvalidStateError, InvalidModificationError, NoModificationAllowedError, CORS-same-origin, group of selectors, list of css page selectors, CSSCharsetRule, ProcessingInstruction, EventTarget, EventListener, Event, EventInit, Element, Range, Node, Text, style, CSSFontFaceRule, -webkit-transform
20 Ignored Vars: m1, m2, camel_cased_attribute, webkit_cased_attribute, dashed_attribute
21 </pre>
23 <pre class='anchors'>
24 urlPrefix: https://html.spec.whatwg.org/multipage/
25 urlPrefix: infrastructure.html
26 type: dfn
27 text: html elements
28 text: tree order
29 text: document base url
30 text: content-type metadata; url: #content-type
31 urlPrefix: browsers.html
32 type: interface; text: WindowProxy
33 type: dfn
34 text: browsing context
35 text: auxiliary browsing context
36 text: familiar with
37 text: same origin
38 urlPrefix: webappapis.html
39 type: dfn
40 text: responsible browsing context
41 text: incumbent settings object
42 text: event loop
43 text: event handler
44 text: event handler event type
45 text: event handler IDL attributes
46 urlPrefix: infrastructure.html
47 type: dfn
48 text: split a string on commas
49 text: skip whitespace
50 text: collect a sequence of characters
51 text: space character
52 text: rules for parsing integers
53 urlPrefix: xhtml.html
54 type: dfn
55 text: xml parser
56 urlPrefix: semantics.html
57 type: dfn
58 text: a style sheet that is blocking scripts
59 text: style sheet ready
60 urlPrefix: https://dom.spec.whatwg.org/#concept-
61 type: dfn
62 text: context object
63 text: dispatch; url: event-dispatch
64 text: event
65 text: event listener
66 text: quirks mode; url: document-quirks
67 text: fire an event; url: event-fire
68 text: node document
69 text: document url
70 urlPrefix: http://www.w3.org/TR/CSS21/visuren.html
71 type: dfn; text: anonymous block box; url: #anonymous-block-level
72 urlPrefix: http://heycam.github.io/webidl/#
73 type: interface; urlPrefix: idl-
74 text: double
75 text: long
76 type: dfn; urlPrefix: dfn-
77 text: converted to an IDL value
78 text: throw
79 text: supported property indices
80 urlPrefix: https://encoding.spec.whatwg.org/#; spec: ENCODING
81 type: dfn; text: get an encoding; url: concept-encoding-get
82 urlPrefix: https://url.spec.whatwg.org/#concept-
83 type: dfn
84 text: absolute url
85 text: URL
86 text: URL parser
87 text: URL serializer
88 urlPrefix: http://www.w3.org/TR/xml-stylesheet/#
89 type: dfn; text: xml-stylesheet processing instruction
90 type: dfn; text: pseudo-attribute
91 urlPrefix: https://fetch.spec.whatwg.org/#concept-
92 type: dfn;
93 text: fetch
94 text: request
95 for: request
96 text: url
97 text: origin
98 text: referrer
99 text: network error
100 </pre>
102 <pre class='link-defaults'>
103 spec:css-display-3; type:value; for:display; text:table
104 spec:css-color-4; type:property; text:color
105 spec:css-position-3; type:property; text:left
106 spec:html5; type:element; text:style
107 spec:css-namespaces-3; type:dfn; text:namespace prefix
108 spec:dom-ls; type:interface; text:Document
109 </pre>
111 <script src=https://resources.whatwg.org/file-bug.js async></script>
113 Introduction {#introduction}
114 ============================
116 This document formally specifies the core features of the CSS Object Model (CSSOM). Other documents in the CSSOM family of specifications
117 as well as other CSS related specifications define extensions to these core features.
119 The core features of the CSSOM are oriented towards providing basic capabilities to author-defined scripts to permit access to
120 and manipulation of style related state information and processes.
122 The features defined below are fundamentally based on prior specifications of the W3C DOM Working Group, primarily
123 [[DOM-LEVEL-2-STYLE]]. The purposes of the present document are (1) to improve on that prior work by providing
124 more technical specificity (so as to improve testability and interoperability), (2) to deprecate or remove certain less-widely implemented
125 features no longer considered to be essential in this context, and (3) to newly specify certain extensions that have been
126 or expected to be widely implemented.
128 <!--A full list of the changes to API signatures can be found in <a href="#changes-from-dom-2-style"><cite>Changes from DOM-2 Style</cite></a>.-->
131 Terminology {#terminology}
132 ==========================
134 This specification employs certain terminology from the following documents:
135 <cite>DOM</cite>,
136 <cite>HTML</cite>,
137 <cite>CSS Syntax</cite>,
138 <cite>Encoding</cite>,
139 <cite>URL</cite>,
140 <cite>Fetch</cite>,
141 <cite>Associating Style Sheets with XML documents</cite>
142 and
143 <cite>XML</cite>.
144 [[!DOM]]
145 [[!HTML]]
146 [[!CSS3SYN]]
147 [[!ENCODING]]
148 [[!URL]]
149 [[!FETCH]]
150 [[!XML-STYLESHEET]]
151 [[!XML]]
153 When this specification talks about object
154 <code><var>A</var></code> where <code><var>A</var></code> is actually an interface, it generally means an object implementing interface
155 <code><var>A</var></code>.
157 The terms <dfn>set</dfn> and <dfn>unset</dfn> to refer to the true and
158 false values of binary flags or variables, respectively. These terms are also used as verbs in which case they refer to
159 mutating some value to make it true or false, respectively.
161 The term <dfn export>supported styling language</dfn> refers to CSS.
163 Note: If another styling language becomes supported in user agents, this specification is expected to be updated as necessary.
165 The term <dfn export>supported CSS property</dfn> refers to a CSS property that the user agent implements,
166 and that is defined to be a case-insensitive property in the CSS specification.
167 A <a>supported CSS property</a> must be in its lowercase form for the purpose of comparisons this specification.
169 In this specification the ''::before'' and ''::after'' pseudo-elements
170 are assumed to exist for all elements even if no box is generated for them.
172 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
173 e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.
175 Unless otherwise stated, string comparisons are done in a <a>case-sensitive</a> manner.
178 Common Serializing Idioms {#common-serializing-idioms}
179 ------------------------------------------------------
181 To <dfn>escape a character</dfn> means to create a string of
182 "<code>\</code>" (U+005C), followed by the character.
184 To <dfn lt="escape a character as code point|escaped as code point">escape a character as code point</dfn> means to create a
185 string of "<code>\</code>" (U+005C), followed by the Unicode code point as
186 the smallest possible number of hexadecimal digits in the range 0-9 a-f
187 (U+0030 to U+0039 and U+0061 to U+0066) to represent the code point in
188 base 16, followed by a single SPACE (U+0020).
190 To <dfn export>serialize an identifier</dfn> means to create a string represented
191 by the concatenation of, for each character of the identifier:
193 <ul>
194 <li>If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD).
195 <li>If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F, then the character
196 <a>escaped as code point</a>.
197 <li>If the character is the first character and is in the range \[0-9]
198 (U+0030 to U+0039), then the character
199 <a>escaped as code point</a>.
200 <li>If the character is the second character and is in the range \[0-9]
201 (U+0030 to U+0039) and the first character is a "<code>-</code>"
202 (U+002D), then the character
203 <a>escaped as code point</a>.
204 <li>If the character is the first character and is a "<code>-</code>" (U+002D),
205 and there is no second character,
206 then the <a lt="escape a character">escaped</a> character.
207 <li>If the character is not handled by one of the above rules and is
208 greater than or equal to U+0080, is "<code>-</code>" (U+002D) or
209 "<code>_</code>" (U+005F), or is in one of the ranges \[0-9] (U+0030 to
210 U+0039), \[A-Z] (U+0041 to U+005A), or \[a-z] (U+0061 to U+007A), then the character
211 itself.
212 <li>Otherwise, the <a lt="escape a character">escaped</a>
213 character.
214 </ul>
216 To <dfn export>serialize a string</dfn> means to create a string represented
217 by '"' (U+0022), followed by the result of applying the rules
218 below to each character of the given string, followed by
219 '"' (U+0022):
221 <ul>
222 <li>If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD)
223 <a>escaped as code point</a>.
224 <li>If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F, the character
225 <a>escaped as code point</a>.
226 <li>If the character is '"' (U+0022) or "<code>\</code>"
227 (U+005C), the <a lt="escape a character">escaped</a> character.
228 <li>Otherwise, the character itself.
229 </ul>
231 Note: "<code>'</code>" (U+0027) is not escaped because strings
232 are always serialized with '"' (U+0022).
234 To <dfn export>serialize a URL</dfn> means to create a string represented by
235 "<code>url(</code>", followed by the
236 <a lt="serialize a string">string escaped</a> value of the given
237 string, followed by "<code>)</code>".
239 To <dfn export>serialize a comma-separated list</dfn> concatenate all items of
240 the list in list order while separating them by "<code>, </code>", i.e.,
241 COMMA (U+002C) followed by a single SPACE (U+0020).
243 To <dfn export>serialize a whitespace-separated list</dfn> concatenate all
244 items of the list in list order while separating them by "<code> </code>", i.e.,
245 a single SPACE (U+0020).
247 Note: When serializing a list according to the above rules,
248 extraneous whitespace is not inserted prior to the first item or subsequent to
249 the last item. Unless otherwise specified, an empty list is serialized as the
250 empty string.
253 Media Queries {#media-queries}
254 ==============================
256 Media queries are defined by the Media Queries specification. This
257 section defines various concepts around media queries, including their API
258 and serialization form.
260 <!-- XXX ref -->
263 Parsing Media Queries {#parsing-media-queries}
264 ----------------------------------------------
266 To <dfn export>parse a media query list</dfn> for a
267 given string <var>s</var> into a media query list is defined in
268 the Media Queries specification. Return the list of one or more media
269 queries that the algorithm defined there gives. <!-- XXX ref -->
271 Note: A media query that ends up being "ignored" will turn
272 into "<code>not all</code>".
274 To <dfn export>parse a media query</dfn> for a given string
275 <var>s</var> means to follow the
276 <a>parse a media query list</a> steps and return null if more
277 than one media query is returned or a media query if a
278 single media query is returned.
280 Note: Again, a media query that ends up being "ignored" will
281 turn into "<code>not all</code>".
284 Serializing Media Queries {#serializing-media-queries}
285 ------------------------------------------------------
287 To
288 <dfn export>serialize a media query list</dfn>
289 run these steps:
291 <ol>
292 <li>If the media query list is empty return the empty string and
293 terminate these steps.
295 <li><a lt="serialize a media query">Serialize</a> each media query in the list of media queries, in the same order as they appear in the list of
296 media queries, and then <a lt="serialize a comma-separated list">serialize</a> the list.
297 </ol>
299 To
300 <dfn export>serialize a media query</dfn> let
301 <var>s</var> be the empty string, run the steps below, and
302 finally return <var>s</var>:
304 <ol>
305 <li>If the media query is negated append "<code>not</code>", followed
306 by a single SPACE (U+0020), to <var>s</var>.
308 <li>Let <var>type</var> be the media type of the media query,
309 <a lt="serialize an identifier">escaped</a> and
310 <a>converted to ASCII lowercase</a>.
312 <li>If the media query does not contain media features append
313 <var>type</var>, to <var>s</var>,
314 then return <var>s</var> and terminate this algorithm.
316 <li>If <var>type</var> is not "<code>all</code>" or if the
317 media query is negated append <var>type</var>, followed by a
318 single SPACE (U+0020), followed by "<code>and</code>", followed by a single SPACE
319 (U+0020), to <var>s</var>.
321 <li>Sort the media features in lexicographical order.
323 <li>
324 Then, for each media feature:
326 <ol>
327 <li>Append a "<code>(</code>" (U+0028), followed by the media feature
328 name, <a>converted to ASCII lowercase</a>,
329 to <var>s</var>.
331 <li>If a value is given append a "<code>:</code>" (U+003A), followed
332 by a single SPACE (U+0020), followed by the
333 <a lt="serialize a media feature value">serialized media feature value</a>,
334 to <var>s</var>.
336 <li>Append a "<code>)</code>" (U+0029) to
337 <var>s</var>.
339 <li>If this is not the last media feature append a single SPACE (U+0020),
340 followed by "<code>and</code>", followed by a single SPACE (U+0020), to
341 <var>s</var>.
342 </ol>
344 </ol>
346 <div class="example">
347 Here are some examples of input (first column) and output (second
348 column):
350 <table class="complex data">
351 <thead>
352 <tr><th>Input<th>Output
353 <tbody>
354 <tr>
355 <td><pre>not screen and (min-WIDTH:5px) AND (max-width:40px)</pre>
356 <td><pre>not screen and (max-width: 40px) and (min-width: 5px)</pre>
357 <tr>
358 <td><pre>all and (color) and (color)</pre>
359 <td><pre>(color)</pre>
360 </table>
361 </div>
365 ### Serializing Media Feature Values ### {#serializing-media-feature-values}
367 Issue: This should probably be done in terms of mapping it to
368 serializing CSS values as media features are defined in terms of CSS
369 values after all.
371 To <dfn export>serialize a media feature value</dfn>
372 named <var>v</var> locate <var>v</var> in the first
373 column of the table below and use the serialization format described in
374 the second column:
376 <table class="complex data" spec=mediaqueries-4>
377 <thead>
378 <tr>
379 <th>Media Feature
380 <th>Serialization
381 <tbody>
382 <tr>
383 <td>'width'
384 <td>...
385 <tr>
386 <td>'height'
387 <td>...
388 <tr>
389 <td>'device-width'
390 <td>...
391 <tr>
392 <td>'device-height'
393 <td>...
394 <tr>
395 <td>'orientation'
396 <td>
397 If the value is ''portrait'': "<code>portrait</code>".
398 If the value is ''landscape'': "<code>landscape</code>".
399 <tr>
400 <td>'aspect-ratio'
401 <td>...
402 <tr>
403 <td>'device-aspect-ratio'
404 <td>...
405 <tr>
406 <td>'color'
407 <td>...
408 <tr>
409 <td>'color-index'
410 <td>...
411 <tr>
412 <td>'monochrome'
413 <td>...
414 <tr>
415 <td>'resolution'
416 <td>...
417 <tr>
418 <td>'scan'
419 <td>
420 If the value is ''progressive'': "<code>progressive</code>".
421 If the value is ''interlace'': "<code>interlace</code>".
422 <tr>
423 <td>'grid'
424 <td>...
425 </table>
427 Other specifications can extend this table and vendor-prefixed media
428 features can have custom serialization formats as well.
431 Comparing Media Queries {#comparing-media-queries}
432 --------------------------------------------------
434 To
435 <dfn export>compare media queries</dfn>
436 <var>m1</var> and <var>m2</var> means to
437 <a lt="serialize a media query">serialize</a> them both and
438 return true if they are a
439 <a>case-sensitive</a> match and false if they
440 are not.
443 The {{MediaList}} Interface {#the-medialist-interface}
444 ------------------------------------------------------
446 <!--
447 //
448 // All members defined since DOM-2 Style. The only differences are:
449 //
450 // 1. addition of stringifier qualifier on mediaText
451 // 2. addition of getter qualifier on item
452 // 3. removal of raises(DOMException) from {append,delete}Medium
453 //
454 -->
456 An object that implements the <code>MediaList</code> interface has an associated <dfn export for=MediaList>collection of media queries</dfn>.
458 <pre class=idl>
459 [ArrayClass]
460 interface MediaList {
461 [TreatNullAs=EmptyString] stringifier attribute DOMString mediaText;
462 readonly attribute unsigned long length;
463 getter DOMString? item(unsigned long index);
464 void appendMedium(DOMString medium);
465 void deleteMedium(DOMString medium);
466 };
467 </pre>
469 The object's <a>supported property indices</a> are the numbers in the range zero to one less than the number of media queries
470 in the <a>collection of media queries</a> represented by the collection. If there are no such media queries, then there are no
471 <a>supported property indices</a>.
473 To <dfn export>create a <code>MediaList</code> object</dfn> with a string <var>text</var>, run the following steps:
474 <ol>
475 <li>Create a new <code>MediaList</code> object.
476 <li>Set its {{MediaList/mediaText}} attribute to <var>text</var>.
477 <li>Return the newly created <code>MediaList</code> object.
478 </ol>
480 The <dfn attribute for=MediaList>mediaText</dfn> attribute, on getting, must return a
481 <a lt="serialize a media query list">serialization</a> of the <a>collection of media queries</a>.
482 Setting the {{MediaList/mediaText}} attribute must run these steps:
483 <ol>
484 <li>Empty the <a>collection of media queries</a>.
485 <li>If the given value is the empty string terminate these steps.
486 <li>Append all the media queries as a result of <a lt="parse a media query list">parsing</a> the given
487 value to the <a>collection of media queries</a>.
488 </ol>
490 The <dfn method for=MediaList>item(<var>index</var>)</dfn> method must return the media query in the <a>collection of media
491 queries</a> given by <var>index</var>, or null, if <var>index</var> is greater than or equal to the number of media queries in the
492 <a>collection of media queries</a>.
494 The <dfn attribute for=MediaList>length</dfn> attribute must return the number of media queries in the <a>collection of media
495 queries</a>.
497 The <dfn method for=MediaList>appendMedium(<var>medium</var>)</dfn> method must run these steps:
498 <ol>
499 <li>Let <var>m</var> be the result of <a lt="parse a media query">parsing</a> the given value.
500 <li>If <var>m</var> is null terminate these steps.
501 <li>If <a lt="compare media queries">comparing</a> <var>m</var> with any of the media queries in the
502 <a>collection of media queries</a> returns true terminate these steps.
503 <li>Append <var>m</var> to the <a>collection of media queries</a>.
504 </ol>
506 The <dfn method for=MediaList>deleteMedium(<var>medium</var>)</dfn> method must run these steps:
507 <ol>
508 <li>Let <var>m</var> be the result of <a lt="parse a media query">parsing</a> the given value.
509 <li>If <var>m</var> is null terminate these steps.
510 <li>Remove any media query from the <a>collection of media queries</a> for which
511 <a lt="compare media queries">comparing</a> the media query with <var>m</var> returns true.
512 </ol>
514 Selectors {#selectors}
515 ======================
517 Selectors are defined in the Selectors specification. This section
518 mainly defines how to serialize them. <!-- XXX ref -->
520 <!-- XXX ref universal selector etc? some are in A some not -->
523 Parsing Selectors {#parsing-selectors}
524 --------------------------------------
526 To
527 <dfn export>parse a group of selectors</dfn>
528 means to parse the value using the <code>selectors_group</code>
529 production defined in the Selectors specification and return either a
530 group of selectors if parsing did not fail or null if parsing did
531 fail. <!-- XXX ref -->
534 Serializing Selectors {#serializing-selectors}
535 ----------------------------------------------
537 <!-- http://dump.testsuite.org/2009/cssom/serializing-selectors.htm -->
539 To
540 <dfn export>serialize a group of selectors</dfn>
541 <a lt="serialize a selector">serialize</a> each selector in the
542 group of selectors and then
543 <a lt="serialize a comma-separated list">serialize</a> the
544 group.
546 To <dfn export>serialize a selector</dfn> let
547 <var>s</var> be the empty string, run the steps below for each
548 part of the chain of the selector, and finally return
549 <var>s</var>:
551 <ol>
552 <li>If there is only one <a>simple selector</a> in the
553 <a>compound selectors</a> which is a
554 <a>universal selector</a>, append the result of
555 <a lt="serialize a simple selector">serializing</a> the
556 <a>universal selector</a> to <var>s</var>.
558 <li>Otherwise, for each <a>simple selector</a> in the
559 <a>compound selectors</a> that is not a
560 universal selector of which the
561 <a>namespace prefix</a> maps to a namespace that is not the
562 <a>default namespace</a>
563 <a lt="serialize a simple selector">serialize</a> the
564 <a>simple selector</a> and append the result to
565 <var>s</var>.
567 <li>If this is not the last part of the chain of the selector append a
568 single SPACE (U+0020), followed by the combinator
569 "<code>></code>",
570 "<code>+</code>",
571 "<code>~</code>",
572 "<code>>></code>",
573 "<code>||</code>",
574 as appropriate, followed by another single SPACE (U+0020) if the combinator was
575 not whitespace, to <var>s</var>.
577 <li>If this is the last part of the chain of the selector and there is
578 a pseudo-element, append "<code>::</code>" followed by the name of the
579 pseudo-element, to <var>s</var>.
580 </ol>
583 To
584 <dfn export>serialize a simple selector</dfn>
585 let <var>s</var> be the empty string, run the steps below, and
586 finally return <var>s</var>:
588 <dl class="switch">
589 <dt>type selector
590 <dt>universal selector
591 <dd>
592 <ol>
593 <li>If the <a>namespace prefix</a> maps to a namespace that is
594 not the <a>default namespace</a> and is not the
595 null namespace (not in a namespace) append the
596 <a lt="serialize an identifier">escaped</a>
597 <a>namespace prefix</a>, followed by a "<code>|</code>" (U+007C)
598 to <var>s</var>.
600 <li>If the <a>namespace prefix</a> maps to a namespace that is
601 the null namespace (not in a namespace) append
602 "<code>|</code>" (U+007C) to <var>s</var>.
603 <!-- This includes |* -->
605 <li>If this is a type selector append the
606 <a lt="serialize an identifier">escaped</a> element name to
607 <var>s</var>.
609 <li>If this is a universal selector append "<code>*</code>" (U+002A)
610 to <var>s</var>.
611 </ol>
614 <dt>attribute selector
615 <dd>
616 <ol>
617 <li>Append "<code>[</code>" (U+005B) to
618 <var>s</var>.
620 <li>If the <a>namespace prefix</a> maps to a namespace that is
621 not the null namespace (not in a namespace) append the
622 <a lt="serialize an identifier">escaped</a>
623 <a>namespace prefix</a>, followed by a "<code>|</code>" (U+007C)
624 to <var>s</var>.
626 <li>Append the <a lt="serialize an identifier">escaped</a>
627 attribute name to <var>s</var>.
629 <li>If there is an attribute value specified, append
630 "<code>=</code>",
631 "<code>~=</code>",
632 "<code>|=</code>",
633 "<code>^=</code>",
634 "<code>$=</code>", or
635 "<code>*=</code>"
636 as appropriate (depending on the type of attribute selector), followed
637 by the <a lt="serialize a string">string escaped</a>
638 attribute value, to <var>s</var>.
640 <li>If the attribute selector has the case-sensitivity flag present,
641 append "<code> i</code>" (U+0020 U+0069) to <var>s</var>.
643 <li>Append "<code>]</code>" (U+005D) to
644 <var>s</var>.
645 </ol>
648 <dt>class selector
649 <dd>Append a "<code>.</code>" (U+002E), followed by the
650 <a lt="serialize an identifier">escaped</a> class name to
651 <var>s</var>.
653 <dt>ID selector
654 <dd>Append a "<code>#</code>" (U+0023), followed by the
655 <a lt="serialize an identifier">escaped</a> ID to
656 <var>s</var>.
658 <dt>pseudo-class
659 <dd>
660 If the pseudo-class does not accept arguments append
661 "<code>:</code>" (U+003A), followed by the name of the pseudo-class, to
662 <var>s</var>.
664 Otherwise, append "<code>:</code>" (U+003A), followed by the name of
665 the pseudo-class, followed by "<code>(</code>" (U+0028), followed by the
666 value of the pseudo-class argument(s) determined as per below, followed by
667 "<code>)</code>" (U+0029), to <var>s</var>.
669 <dl class="switch">
670 <dt><code>:lang()</code>
671 <dd>The value of each argument <a lt="serialize a string">string escaped</a>,
672 preserving relative order,
673 separated by "<code>, </code>" (U+002C U+0020).
675 <dt><code>:nth-child()</code>
676 <dt><code>:nth-last-child()</code>
677 <dt><code>:nth-of-type()</code>
678 <dt><code>:nth-last-of-type()</code>
679 <dd>The result of serializing the value using the rules to <a>serialize an <an+b> value</a>.
681 <dt><code>:not()</code>
682 <dd>The result of serializing the value using the rules for
683 <a lt="serialize a group of selectors">serializing a group of selectors</a>.
684 </dl>
686 </dl>
689 CSS {#css-object-model}
690 =======================
693 CSS Style Sheets {#css-style-sheets}
694 ------------------------------------
696 A <dfn export>CSS style sheet</dfn> is an abstract concept that
697 represents a style sheet as defined by the CSS specification. In the CSSOM a
698 <a>CSS style sheet</a> is represented as a {{CSSStyleSheet}} object. A
699 <a>CSS style sheet</a> has a number of associated state items:
701 <dl dfn-for="CSSStyleSheet">
702 <dt><dfn id=concept-css-style-sheet-type>type</dfn>
703 <dd>The literal string "<code>text/css</code>".
705 <dt><dfn id=concept-css-style-sheet-location>location</dfn>
706 <dd>Specified when created. The <a>absolute URL</a> of the first request of the
707 <a>CSS style sheet</a> or null if the <a>CSS style sheet</a> was
708 embedded. Does not change during the lifetime of the <a>CSS style sheet</a>.
710 <dt><dfn id=concept-css-style-sheet-parent-css-style-sheet>parent CSS style sheet</dfn>
711 <dd>Specified when created. The <a>CSS style sheet</a> that is the parent of the
712 <a>CSS style sheet</a> or null if there is no associated parent.
714 <dt><dfn id=concept-css-style-sheet-owner-node>owner node</dfn>
715 <dd>Specified when created. The DOM node associated with the <a>CSS style sheet</a> or
716 null if there is no associated DOM node.
718 <dt><dfn id=concept-css-style-sheet-owner-css-rule>owner CSS rule</dfn>
719 <dd>Specified when created. The <a for=/>CSS rule</a>
720 in the <a for=CSSStyleSheet>parent CSS style sheet</a>
721 that caused the inclusion of the <a>CSS style sheet</a> or null if
722 there is no associated rule.
724 <dt><dfn id=concept-css-style-sheet-media>media</dfn>
725 <dd>
726 Specified when created. The {{MediaList}} object associated with the
727 <a>CSS style sheet</a>.
729 If this property is specified to a string, the <a>media</a> must be set to the return value of invoking
730 <a>create a <code>MediaList</code> object</a> steps for that string.
732 If this property is specified to an attribute of the <a for=CSSStyleSheet>owner node</a>, the
733 <a>media</a> must be set to the return value of invoking <a>create a <code>MediaList</code> object</a> steps
734 for the value of that attribute. Whenever the attribute is set, changed or removed, the <a>media</a>'s
735 {{MediaList/mediaText}} attribute must be set to the new value of the attribute, or to null if the attribute is absent.
737 Note: Changing the <a>media</a>'s {{MediaList/mediaText}} attribute does not
738 change the corresponding attribute on the <a for=CSSStyleSheet>owner node</a>.
741 <dt><dfn id=concept-css-style-sheet-title>title</dfn>
742 <dd>
743 Specified when created. The title of the <a>CSS style sheet</a>, which can be the empty string.
745 <div class="example">
746 In the following, the <a>title</a> is non-empty
747 for the first style sheet, but is empty for the second and third style sheets.
749 <pre>
750 <style lt="papaya whip">
751 body { background: #ffefd5; }
752 </style>
753 </pre>
755 <pre>
756 <style lt="">
757 body { background: orange; }
758 </style>
759 </pre>
761 <pre>
762 <style>
763 body { background: brown; }
764 </style>
765 </pre>
766 </div>
768 If this property is specified to an attribute of the <a for=CSSStyleSheet>owner node</a>, the
769 <a>title</a> must be set to the value of that attribute. Whenever the attribute is set, changed or removed, the
770 <a>title</a> must be set to the new value of the attribute, or to the empty string if the attribute is absent.
774 <dt><dfn id=concept-css-style-sheet-alternate-flag>alternate flag</dfn>
775 <dd>
776 Specified when created. Either set or unset. Unset by default.
778 <div class="example">
779 The following <a>CSS style sheets</a> have
780 their <a>alternate flag</a> set:
782 <pre><?xml-stylesheet alternate="yes" lt="x" href="data:text/css,…"?></pre>
784 <pre><link rel="alternate stylesheet" lt="x" href="data:text/css,…"></pre>
785 </div>
788 <dt><dfn id=concept-css-style-sheet-disabled-flag>disabled flag</dfn>
789 <dd>
790 Either set or unset. Unset by default.
792 Note: Even when unset it does not necessarily mean that the
793 <a>CSS style sheet</a> is actually used for rendering.
797 <dt><dfn id=concept-css-style-sheet-css-rules>CSS rules</dfn>
798 <dd>The CSS rules associated with the
799 <a>CSS style sheet</a>.
801 <dt><dfn id=concept-css-style-sheet-origin-clean-flag>origin-clean flag</dfn>
802 <dd>Specified when created. Either set or unset. If it is set, the API allows reading and modifying of the <a for=CSSStyleSheet>CSS rules</a>.
803 </dl>
806 ### The {{StyleSheet}} Interface ### {#the-stylesheet-interface}
808 <!--
809 //
810 // All members defined since DOM-2 Style. Only difference
811 // is addition of [PutForwards=mediaText], which is presently
812 // not defined in CSSOM draft.
813 //
814 -->
816 The {{StyleSheet}} interface represents an abstract, base style sheet.
818 <pre class=idl>
819 interface StyleSheet {
820 readonly attribute DOMString type;
821 readonly attribute DOMString? href;
822 readonly attribute (Element or ProcessingInstruction)? ownerNode;
823 readonly attribute StyleSheet? parentStyleSheet;
824 readonly attribute DOMString? title;
825 [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
826 attribute boolean disabled;
827 };
828 </pre>
830 The <dfn attribute for=StyleSheet>type</dfn> attribute must return the <a for=CSSStyleSheet>type</a>.
832 The <dfn attribute for=StyleSheet>href</dfn> attribute must return the <a>location</a>.
834 The <dfn attribute for=StyleSheet>ownerNode</dfn> attribute must return the <a for=CSSStyleSheet>owner node</a>.
836 The <dfn attribute for=StyleSheet>parentStyleSheet</dfn> attribute must return the
837 <a for=CSSStyleSheet>parent CSS style sheet</a>.
839 The <dfn attribute for=StyleSheet>title</dfn> attribute must return the <a>title</a> or null if
840 <a>title</a> is the empty string.
842 The <dfn attribute for=StyleSheet>media</dfn> attribute must return the <a>media</a>.
844 The <dfn attribute for=StyleSheet>disabled</dfn> attribute, on getting, must return true if the
845 <a>disabled flag</a>
846 is set, or false otherwise. On setting, the {{StyleSheet/disabled}} attribute must set the
847 <a>disabled flag</a> if the new value is true, or unset the
848 <a>disabled flag</a> otherwise.
851 ### The {{CSSStyleSheet}} Interface ### {#the-cssstylesheet-interface}
853 <!--
854 //
855 // All members defined since DOM-2 Style. The only differences are:
856 //
857 // 1. removal of raises(DOMException) on {insert,delete}Rule operations.
858 //
859 -->
861 The {{CSSStyleSheet}} interface represents a <a>CSS style sheet</a>.
863 <pre class=idl>
864 interface CSSStyleSheet : StyleSheet {
865 readonly attribute CSSRule? ownerRule;
866 [SameObject] readonly attribute CSSRuleList cssRules;
867 unsigned long insertRule(DOMString rule, unsigned long index);
868 void deleteRule(unsigned long index);
869 };
870 </pre>
872 The <dfn attribute for=CSSStyleSheet>ownerRule</dfn> attribute must return the <a for=CSSStyleSheet>owner CSS rule</a>.
873 If a value other than null is ever returned, then that same value must always be returned on each get access.
875 The <dfn attribute for=CSSStyleSheet>cssRules</dfn> attribute must follow these steps:
877 <ol>
878 <li>If the <a>origin-clean flag</a> is unset,
879 <a>throw</a> a {{SecurityError}} exception.
880 <li>Return a read-only, live {{CSSRuleList}} object representing
881 the <a for=CSSStyleSheet>CSS rules</a>.
882 Note: Even though the returned {{CSSRuleList}} object is read-only (from the perspective of
883 client-authored script), it can nevertheless change over time due to its liveness status. For example, invoking
884 the {{CSSStyleSheet/insertRule()}} or {{CSSStyleSheet/deleteRule()}} methods can result in
885 mutations reflected in the returned object.
886 </ol>
888 The <dfn method for=CSSStyleSheet>insertRule(<var>rule</var>, <var>index</var>)</dfn> method must run the following steps:
890 <ol>
891 <li>If the <a>origin-clean flag</a> is unset,
892 <a>throw</a> a {{SecurityError}} exception.
893 <li>Return the result of invoking <a>insert a CSS rule</a> <var>rule</var> in the <a for=CSSStyleSheet>CSS rules</a>
894 at <var>index</var>.
895 </ol>
897 The <dfn method for=CSSStyleSheet>deleteRule(<var>index</var>)</dfn> method must run the following steps:
899 <ol>
900 <li>If the <a>origin-clean flag</a> is unset,
901 <a>throw</a> a {{SecurityError}} exception.
902 <li><a>Remove a CSS rule</a> in the <a for=CSSStyleSheet>CSS rules</a> at <var>index</var>.
903 </ol>
905 CSS Style Sheet Collections {#css-style-sheet-collections}
906 ----------------------------------------------------------
908 Below various new concepts are defined that are associated with each
909 {{Document}} object.
911 Each {{Document}} has an associated list of zero or more
912 <a>CSS style sheets</a>, named the
913 <dfn>document CSS style sheets</dfn>. This is
914 an ordered list that contains all
915 <a>CSS style sheets</a> associated with the
916 {{Document}}, in
917 <a>tree order</a>, with
918 <a>CSS style sheets</a> created from HTTP
919 <code>Link</code> headers first, if any, in header
920 order.
922 To <dfn>create a CSS style sheet</dfn>, run these
923 steps:
925 <ol>
926 <li>Create a new <a>CSS style sheet</a> object and set its
927 properties as specified.
929 <li>
930 Then run the <a>add a CSS style sheet</a> steps for the newly created <a>CSS style sheet</a>.
932 <p class=warning>If the <a>origin-clean flag</a> is unset, this can expose information from the user's
933 intranet.
934 </ol>
936 To <dfn>add a CSS style sheet</dfn>, run these
937 steps:
939 <ol>
940 <li>Add the <a>CSS style sheet</a> to the list of
941 <a>document CSS style sheets</a> at the appropriate location. The
942 remainder of these steps deal with the
943 <a>disabled flag</a>.
945 <li>If the <a>disabled flag</a> is set, terminate
946 these steps.
948 <li>If the <a>title</a> is not the empty string, the
949 <a>alternate flag</a> is unset, and
950 <a>preferred CSS style sheet set name</a> is the empty string
951 <a>change the preferred CSS style sheet set name</a> to the
952 <a>title</a>.
954 <li>
955 If any of the following is true unset the
956 <a>disabled flag</a> and terminate these steps:
958 <ul>
959 <li>The <a>title</a> is the empty string.
960 <li>The <a>last CSS style sheet set name</a> is null and the
961 <a>title</a> is a
962 <a>case-sensitive</a> match
963 for the <a>preferred CSS style sheet set name</a>.
964 <li>The <a>title</a> is a
965 <a>case-sensitive</a> match for the
966 <a>last CSS style sheet set name</a>.
967 </ul>
970 <li>Set the <a>disabled flag</a>.
971 </ol>
973 To <dfn>remove a CSS style sheet</dfn>, run these steps:
975 <ol>
976 <li>Remove the <a>CSS style sheet</a> from the list of <a>document CSS style sheets</a>.
978 <li>Set the <a>CSS style sheet</a>'s <a for=CSSStyleSheet>parent CSS style sheet</a>,
979 <a for=CSSStyleSheet>owner node</a> and <a for=CSSStyleSheet>owner CSS rule</a> to null.
981 <!-- "associated CSS style sheet" is defined in terms of owner node, so we don't need to set it to null explicitly -->
983 <!-- XXX does anything need to happen wrt alternate style sheets? what if the last style sheet with the preferred style sheet set name is removed? -->
984 </ol>
986 A <dfn>persistent CSS style sheet</dfn> is a
987 <a>CSS style sheet</a> from the <a>document CSS style sheets</a>
988 whose <a>title</a> is the empty string and whose
989 <a>alternate flag</a> is unset.
991 A <dfn>CSS style sheet set</dfn> is an ordered
992 collection of one or more <a>CSS style sheets</a>
993 from the <a>document CSS style sheets</a> which have an identical
994 <a>title</a> that is not the empty string.
996 A <dfn>CSS style sheet set name</dfn> is the
997 <a>title</a> the <a>CSS style sheet set</a> has in
998 common.
1000 An <dfn>enabled CSS style sheet set</dfn> is a
1001 <a>CSS style sheet set</a> of which each <a>CSS style sheet</a> has
1002 its <a>disabled flag</a> unset.
1004 To <dfn>enable a CSS style sheet set</dfn>
1005 with name <var>name</var>, run these steps:
1007 <ol>
1008 <li>If <var>name</var> is the empty string, set the
1009 <a>disabled flag</a> for each <a>CSS style sheet</a>
1010 that is in a <a>CSS style sheet set</a> and terminate these steps.
1012 <li>Unset the <a>disabled flag</a> for each
1013 <a>CSS style sheet</a> in a <a>CSS style sheet set</a> whose
1014 <a>CSS style sheet set name</a> is a
1015 <a>case-sensitive</a> match for
1016 <var>name</var> and set it for all other
1017 <a>CSS style sheets</a> in a
1018 <a>CSS style sheet set</a>.
1019 </ol>
1021 To <dfn>select a CSS style sheet set</dfn>
1022 with name <var>name</var>, run these steps:
1024 <ol>
1025 <li><a>enable a CSS style sheet set</a> with name
1026 <var>name</var>.
1028 <li>Set <a>last CSS style sheet set name</a> to
1029 <var>name</var>.
1030 </ol>
1032 A <dfn>last CSS style sheet set name</dfn>
1033 is a concept to determine what <a>CSS style sheet set</a> was last
1034 <a lt="select a CSS style sheet set">selected</a>. Initially its
1035 value is null.
1037 A
1038 <dfn>preferred CSS style sheet set name</dfn>
1039 is a concept to determine which
1040 <a>CSS style sheets</a> need to have their
1041 <a>disabled flag</a> unset. Initially its value
1042 is the empty string.
1044 To
1045 <dfn>change the preferred CSS style sheet set name</dfn>
1046 with name <var>name</var>, run these steps:
1048 <ol>
1049 <li>Let <var>current</var> be the <a>preferred CSS style sheet set name</a>.
1051 <li>Set <a>preferred CSS style sheet set name</a> to
1052 <var>name</var>.
1054 <li>If <var>name</var> is not a
1055 <a>case-sensitive</a> match for
1056 <var>current</var> and
1057 <a>last CSS style sheet set name</a> is null
1058 <a>enable a CSS style sheet set</a> with name
1059 <var>name</var>.
1060 </ol>
1062 <!-- XXX ought to define "applied"
1064 thoughts:
1065 depends on disabled flag, alternate flag, media queries, sheesh
1066 -->
1069 ### The HTTP Default-Style Header ### {#the-http-default-style-header}
1071 The HTTP <code lt="http-default-style">Default-Style</code> header
1072 can be used to set the <a>preferred CSS style sheet set name</a>
1073 influencing which <a>CSS style sheet set</a> is (initially) the
1074 <a>enabled CSS style sheet set</a>.
1076 For each HTTP <code lt="http-default-style">Default-Style</code>
1077 header, in header order, the user agent must
1078 <a>change the preferred CSS style sheet set name</a> with name being the
1079 value of the header.
1082 ### The {{StyleSheetList}} Interface ### {#the-stylesheetlist-interface}
1084 The {{StyleSheetList}} interface represents an ordered collection of <a>CSS style sheets</a>.
1086 <pre class=idl>
1087 [ArrayClass]
1088 interface StyleSheetList {
1089 getter StyleSheet? item(unsigned long index);
1090 readonly attribute unsigned long length;
1091 };
1092 </pre>
1094 The object's <a>supported property indices</a> are the numbers in the range zero to one less than the number of
1095 <a>CSS style sheets</a> represented by the collection. If there are no such <a>CSS style sheets</a>,
1096 then there are no <a>supported property indices</a>.
1098 The <dfn method for=StyleSheetList>item(<var>index</var>)</dfn> method must return the <var>index</var>th <a>CSS style
1099 sheet</a> in the collection. If there is no <var>index</var>th object in the collection, then the method must return null.
1101 The <dfn attribute for=StyleSheetList>length</dfn> attribute must return the number of <a>CSS style sheets</a>
1102 represented by the collection.
1104 ### Extensions to the {{Document}} Interface ### {#extensions-to-the-document-interface}
1106 <!--
1107 //
1108 // Significant changes since DOM-2 Style:
1109 //
1110 // 1. move styleSheets from separate interface (DocumentStyle) to Document
1111 // 2. addition of selectedStyleSheetSet, lastStyleSheetSet, preferredStyleSheetSet, styleSheetSets, and enableStyleSheetsForSet members
1112 //
1113 // N.B. HTML4 Section 14.3 "External Style Sheets" introduces the concept of a "group [of] alternate style sheets ... under a single style [sheet set] name",
1114 // but does not actually use the term "style sheet set". See http://www.w3.org/TR/html401/present/styles.html#h-14.3 for details.
1115 //
1116 // N.B. According to HTML4 Section 14.3, a "persistent style sheet ... must apply in addition to any alternate style sheet".
1117 //
1118 // N.B. HTML4 Section 14.3 distinguishes the three categories of style sheets as follows:
1119 //
1120 // * persistent - @rel='stylesheet', @title is missing (or empty string?)
1121 // * preferred - @rel='stylesheet', @title is present (and non-empty?)
1122 // * alternate - @rel='alternate stylesheet', @title is present (and non-empty?)
1123 //
1124 // Also, HTML5 effectively defines:
1125 //
1126 // * ignored - @rel='alternate stylesheet', @title is missing (or is empty string?) - in this case, LinkStyle.style must evaluate to null
1127 //
1128 // N.B. HTML4 Section 4.3 allows author to specify the default preferred style sheet [set]... [presumably in the case that there are multiple preferred style
1129 // sheet sets]:
1130 //
1131 // * in content - <META http-equiv="Default-Style" content="compact">
1132 // * in http - e.g., using response header - "Default-Style: compact"
1133 // * if multiple of the above forms are present, then the LAST one [seen or parsed] takes precedence; HOWEVER, if two or more LINK elements specify preferred
1134 // style [sheet sets], the FIRST one present in the document takes precedence;
1135 // * preferred style sheets specified using the above (META or HTTP header equivalent) take precedence over those specified with LINK
1136 //
1137 // N.B. CSSOM Draft presently employs the term "Style Sheet Collection"
1138 //
1139 // Spec Issues:
1140 //
1141 // 1. need to specify which style sheets are included in styleSheets, and in which order:
1142 //
1143 // * from Link HTTP header reference
1144 // * from <?xml-stylesheet ...?>
1145 // * from LINK element, @rel='stylesheet'|'alternate stylesheet'
1146 // * from STYLE element
1147 //
1148 // 2. for purpose of comparing two titled (named) style sheets, is title (name) compared on case-sensitive or case-insensitive basis
1149 //
1150 // 3. CSSOM 6.2 appears to imply that one can create a CSSStyleSheet (or StyleSheet) object and add it to a Document. However, that is not the case; rather
1151 // it is necessary to create an HTMLLinkElement or HTMLStyleElement element to indirectly create an empty StyleSheet, then this element can be added to the
1152 // Document.
1153 //
1154 -->
1156 <pre class=idl>
1157 partial interface Document {
1158 [SameObject] readonly attribute StyleSheetList styleSheets;
1159 attribute DOMString? selectedStyleSheetSet;
1160 readonly attribute DOMString? lastStyleSheetSet;
1161 readonly attribute DOMString? preferredStyleSheetSet;
1162 readonly attribute FrozenArray<DOMString> styleSheetSets;
1163 void enableStyleSheetsForSet(DOMString? name);
1164 };
1165 </pre>
1167 The <dfn attribute for=Document>styleSheets</dfn> attribute must return a {{StyleSheetList}} collection representing
1168 the <a>document CSS style sheets</a>.
1169 Note: Because of historical IDL limitations the {{Document/styleSheets}} attribute
1170 used to be on a separate interface, <code>DocumentStyle</code>.
1172 The <dfn attribute for=Document>selectedStyleSheetSet</dfn> attribute, on getting, must run these steps:
1173 <ol>
1174 <li>If there is a single <a>enabled CSS style sheet set</a> and no
1175 other <a>document CSS style sheets</a> with a
1176 <a>title</a> that is not the empty string have the
1177 <a>disabled flag</a> unset, return the
1178 <a>CSS style sheet set name</a> of the
1179 <a>enabled CSS style sheet set</a> and terminate these steps.
1181 <li>Otherwise, if <a>CSS style sheets</a> from
1182 different <a lt="CSS style sheet set">CSS style sheet sets</a> have
1183 their <a>disabled flag</a> unset, return
1184 null and terminate these steps.
1186 <li>
1187 Otherwise, return the empty string.
1189 Note: At this point either all
1190 <a>CSS style sheets</a> with a
1191 <a>title</a> that is not the empty string have the
1192 <a>disabled flag</a> set, or there are no such
1193 <a>CSS style sheets</a>.
1195 </ol>
1197 On setting the
1198 {{Document/selectedStyleSheetSet}}
1199 attribute these steps must be run:
1201 <ol>
1202 <li>If the value is null terminate this set of steps.
1203 <li>Otherwise, <a>select a CSS style sheet set</a> with the name being the
1204 value passed.
1205 </ol>
1207 From the DOM's perspective, all views have the same
1208 {{Document/selectedStyleSheetSet}}.
1209 If a user agent supports multiple views with different selected
1210 alternative style sheets, then this attribute (and the
1211 {{StyleSheet}} interface's
1212 {{StyleSheet/disabled}} attribute)
1213 must return and set the value for the default
1214 view.
1216 The <dfn attribute for=Document>lastStyleSheetSet</dfn> attribute must return the <a>last CSS style sheet set name</a>.
1217 Note: This attribute is initially null.
1219 The <dfn attribute for=Document>preferredStyleSheetSet</dfn> attribute must return the <a>preferred CSS style sheet set
1220 name</a>.
1221 Note: Unlike {{Document/lastStyleSheetSet}},
1222 this attribute is initially the empty string.
1224 The <dfn attribute for=Document>styleSheetSets</dfn> attribute must return a frozen array of the
1225 <a lt="CSS style sheet set name">CSS style sheet set names</a> of the <a lt="CSS style sheet set">CSS style sheet sets</a>, in order of the
1226 <a>document CSS style sheets</a>. The array is live; if the <a>document CSS style sheets</a> change, the array must be updated as appropriate.
1228 The <dfn method for=Document>enableStyleSheetsForSet(<var>name</var>)</dfn> method must, when invoked, run these
1229 steps:
1230 <ol>
1231 <li>If <var>name</var> is null terminate these steps.
1232 <li><a>enable a CSS style sheet set</a> with name <var>name</var>.
1233 </ol>
1234 Note: <a>CSS style sheets</a> with a
1235 <a>title</a> that is the empty string are never affected by this method.
1236 This method does not change the values of the
1237 {{Document/lastStyleSheetSet}} or
1238 {{Document/preferredStyleSheetSet}} attributes.
1241 ### Interaction with the User Interface ### {#interaction-with-the-user-interface}
1243 The user interface of Web browsers that support style sheets
1244 should list the style sheet titles given in the
1245 <code lt="dom-Document-styleSheetSets">styleSheetSets</code> list,
1246 showing the
1247 <code lt="dom-Document-selectedStyleSheetSet">selectedStyleSheetSet</code>
1248 as the selected style sheet set, leaving none selected if it is
1249 null or the empty string, and selecting an extra option
1250 "Basic Page Style" (or similar) if it is the empty string and the
1251 <code lt="dom-Document-preferredStyleSheetSet">preferredStyleSheetSet</code>
1252 is the empty string as well.
1254 Selecting a style sheet from this list should
1255 use the <a>select a CSS style sheet set</a> set of steps. This
1256 (by definition) affects the
1257 <code lt="dom-Document-lastStyleSheetSet">lastStyleSheetSet</code>
1258 attribute.
1260 #### Persisting the selected CSS style sheet set #### {#persisting-the-selected-css-style-sheet-set}
1262 If a user agent persist the <a lt="select a CSS style sheet set">selected</a> <a>CSS style sheet set</a>, it should use
1263 the value of the
1264 <code lt="dom-Document-selectedStyleSheetSet">selectedStyleSheetSet</code>
1265 attribute, or if that is null, the
1266 <code lt="dom-Document-lastStyleSheetSet">lastStyleSheetSet</code>
1267 attribute, when leaving the page (or at some other time) to determine the
1268 set name to store. If that is null then the <a>CSS style sheet set</a> should not be
1269 persisted.
1271 When re-setting the <a>CSS style sheet set</a> to the persisted value (which can
1272 happen at any time, typically at the first time the <a>CSS style sheets</a> are
1273 needed for styling the document, after the <code><head></code> of
1274 the document has been parsed, after any scripts that are not dependent on
1275 computed style have executed), the <a>CSS style sheet set</a>
1276 should be set by using the
1277 <a>select a CSS style sheet set</a> set of steps as if the user had
1278 selected the <a>CSS style sheet set</a> manually.
1280 Note: This specification does not give any suggestions on
1281 how user agents are to decide to persist the <a>CSS style sheet set</a> or whether or
1282 how to persist the <a lt="select a CSS style sheet set">selected</a> <a>CSS style sheet set</a> across pages.
1284 <!-- XXX this UI section suggests we may want to introduce a few more
1285 idioms -->
1288 ### Examples ### {#css-style-sheet-collections-examples}
1290 <div class="example">
1291 Thus, in the following HTML snippet:
1293 <pre>
1294 <link rel="alternate stylesheet" lt="foo" href="a">
1295 <link rel="alternate stylesheet" lt="bar" href="b">
1296 <script>
1297 document.selectedStyleSheetSet = 'foo';
1298 document.styleSheets[1].disabled = false;
1299 </script>
1300 <link rel="alternate stylesheet" lt="foo" href="c">
1301 <link rel="alternate stylesheet" lt="bar" href="d">
1302 </pre>
1304 ...the style sheets that end up enabled are style sheets "a", "b",
1305 and "c", the
1306 <code lt="dom-Document-selectedStyleSheetSet">selectedStyleSheetSet</code>
1307 attribute would return null,
1308 <code lt="dom-Document-lastStyleSheetSet">lastStyleSheetSet</code>
1309 would return "foo", and
1310 <code lt="dom-Document-preferredStyleSheetSet">preferredStyleSheetSet</code>
1311 would return the empty string.
1313 Similarly, in the following HTML snippet:
1315 <pre>
1316 <link rel="alternate stylesheet" lt="foo" href="a">
1317 <link rel="alternate stylesheet" lt="bar" href="b">
1318 <script>
1319 var before = document.preferredStyleSheetSet;
1320 document.styleSheets[1].disabled = false;
1321 </script>
1322 <link rel="stylesheet" lt="foo" href="c">
1323 <link rel="alternate stylesheet" lt="bar" href="d">
1324 <script>
1325 var after = document.preferredStyleSheetSet;
1326 </script>
1327 </pre>
1329 ...the "before" variable will be equal to the empty string, the
1330 "after" variable will be equal to "foo", and style sheets "a" and "c"
1331 will be enabled. This is the case even though the first script block
1332 sets style sheet "b" to be enabled, because upon parsing the
1333 following <code><link></code> element, the
1334 <code lt="dom-Document-preferredStyleSheetSet">preferredStyleSheetSet</code>
1335 is set and the
1336 <code lt="dom-Document-enableStyleSheetsForSet()">enableStyleSheetsForSet()</code>
1337 method is called (since
1338 <code lt="dom-Document-selectedStyleSheetSet">selectedStyleSheetSet</code>
1339 was never set
1340 explicitly, leaving
1341 <code lt="dom-Document-lastStyleSheetSet">lastStyleSheetSet</code> at
1342 null throughout), which changes which style sheets are enabled and which
1343 are not.
1344 </div>
1347 Style Sheet Association {#style-sheet-association}
1348 --------------------------------------------------
1350 This section defines the interface an
1351 <a for=CSSStyleSheet>owner node</a> of a <a>CSS style sheet</a> has to
1352 implement and defines the requirements for
1353 <a>xml-stylesheet processing instructions</a>
1354 and HTTP <code>Link</code> headers when the link
1355 relation type is an
1356 <a>ASCII case-insensitive</a> match for
1357 "<code>stylesheet</code>" since nobody else was interested in
1358 defining this.
1360 Note: The editor is in good hope that HTML and SVG will define the
1361 appropriate processing in their respective specifications, in terms of
1362 this specification, in due course.
1365 ### Fetching CSS style sheets ### {#fetching-css-style-sheets}
1367 To <dfn>fetch a CSS style sheet</dfn> with parsed URL <var>parsed URL</var>, referrer <var>referrer</var>, document
1368 <var>document</var>, optionally a set of parameters <var>parameters</var> (used as input to creating a
1369 <a>request</a>), follow these steps:
1371 <ol>
1372 <li>Let <var>origin</var> be <var>document</var>'s <a>origin</a>.
1374 <li>Let <var>request</var> be a new <a>request</a>, with the
1375 <a for=request>url</a> <var>parsed URL</var>,
1376 <a for=request>origin</a> <var>origin</var>,
1377 <a for=request>referrer</a> <var>referrer</var>, and if specified the set of parameters <var>parameters</var>.
1379 <li>Let <var>response</var> be the result of <a>fetching</a> <var>request</var>.
1381 <li>Wait until <var>response</var> is available.
1383 <li>If <var>response</var> is a <a>network error</a>, return an error.
1385 <li>If <var>document</var> is in <a>quirks mode</a>, <var>response</var> is
1386 <a>CORS-same-origin</a><!--XXX xref--> and the <a>Content-Type metadata</a> of <var>response</var> is not a
1387 <a>supported styling language</a> change the <a>Content-Type metadata</a> of <var>response</var> to
1388 <code>text/css</code>.
1390 <li>If <var>response</var> is not in a <a>supported styling language</a> return an error.
1392 <li>Return <var>response</var>.
1393 </ol>
1395 ### The {{LinkStyle}} Interface ### {#the-linkstyle-interface}
1397 The <dfn>associated CSS style sheet</dfn> of a node is the <a>CSS style sheet</a> in the list of
1398 <a>document CSS style sheets</a> of which the <a for=CSSStyleSheet>owner node</a> implements the {{LinkStyle}}
1399 interface.
1401 <pre class=idl>
1402 [NoInterfaceObject]
1403 interface LinkStyle {
1404 readonly attribute StyleSheet? sheet;
1405 };
1406 </pre>
1408 The <dfn attribute for=LinkStyle>sheet</dfn> attribute must return the <a>associated CSS style sheet</a> for the node or null
1409 if there is no <a>associated CSS style sheet</a>.
1411 <div class="example">
1412 In the following fragment, the first <{style}>
1413 element has a {{LinkStyle/sheet}} attribute that returns a
1414 {{StyleSheet}} object representing the style sheet, but for
1415 the second <{style}> element, the {{LinkStyle/sheet}} attribute returns null,
1416 assuming the user agent supports CSS (<code>text/css</code>), but does
1417 not support the (hypothetical) ExampleSheets (<code>text/example-sheets</code>).
1419 <pre>
1420 <style type="text/css">
1421 body { background:lime }
1422 </style>
1423 </pre>
1424 <pre>
1425 <style type="text/example-sheets">
1426 $(body).background := lime
1427 </style>
1428 </pre>
1429 </div>
1431 Note: Whether or not the node refers to a style sheet is defined
1432 by the specification that defines the semantics of said node.
1435 ### Requirements on specifications ### {#requirements-on-specifications}
1437 Specifications introducing new ways of associating style sheets through
1438 the DOM should define which nodes implement the
1439 {{LinkStyle}} interface. When doing so, they
1440 must also define when a <a>CSS style sheet</a> is
1441 <a lt="create a CSS style sheet">created</a>.
1444 ### Requirements on User Agents Implementing the xml-stylesheet processing instruction ### {#requirements-on-user-agents-implementing-the-xml-stylesheet-processing-instruction}
1445 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1447 <!-- XXX load/error events -->
1449 <pre class="idl">ProcessingInstruction implements LinkStyle;</pre>
1451 The <dfn>prolog</dfn> refers to <a>nodes</a> that are children of the
1452 <a>document</a> and are not <a>following</a> the
1453 {{Element}} child of the <a>document</a>, if any.
1455 When a <code>ProcessingInstruction</code> <a>node</a> <var>node</var> becomes part of the
1456 <a>prolog</a>, is no longer part of the <a>prolog</a>, or has its <a>data</a> changed, these steps
1457 must be run:
1459 <ol>
1460 <li>If an instance of this algorithm is currently running for <var>node</var>, abort that instance, and stop the associated
1461 <a>fetching</a> if applicable.
1463 <li>If <var>node</var> has an <a>associated CSS style sheet</a>, <a lt="remove a CSS style sheet">remove</a> it.
1465 <li>If <var>node</var> is not an <a>xml-stylesheet processing instruction</a>, terminate these steps.
1467 <li>If <var>node</var> does not have an <code>href</code> <a>pseudo-attribute</a>, terminate these steps.
1469 <li>Let <var>title</var> be the value of the
1470 <code>title</code> <a>pseudo-attribute</a> or the empty string if the
1471 <code>title</code> <a>pseudo-attribute</a> is not specified.
1473 <li>If there is an <code>alternate</code> <a>pseudo-attribute</a>
1474 whose value is a <a>case-sensitive</a> match
1475 for "<code>yes</code>" and <var>title</var> is the
1476 empty string terminate these steps.
1478 <li>If there is a <code>type</code> <a>pseudo-attribute</a> whose
1479 value is not a <a>supported styling language</a> the user agent
1480 may terminate these steps.
1482 <li>Let <var>input URL</var> be the value specified by the
1483 <code>href</code> <a>pseudo-attribute</a>.
1485 <li>Let <var>document</var> be <var>node</var>'s <a>node document</a>
1487 <li>Let <var>base URL</var> be <var>document</var>'s <a>document base URL</a>.
1489 <li>Let <var>referrer</var> be <var>document</var>'s <a lt="document URL">address</a>.
1491 <li>Let <var>parsed URL</var> be the return value of invoking the <a>URL parser</a> with the
1492 string <var>input URL</var> and the base URL <var>base URL</var>.
1494 <li>If <var>parsed URL</var> is failure, terminate these steps.
1496 <li>Let <var>response</var> be the result of <a lt="fetch a CSS style sheet">fetching a CSS style sheet</a> with parsed URL <var>parsed URL</var>,
1497 referrer <var>referrer</var> and document <var>document</var>.
1499 <li>If <var>response</var> is an error, terminate these steps.
1501 <li>
1502 <a>Create a CSS style sheet</a> with the following properties:
1504 <dl>
1505 <dt><a>location</a>
1506 <dd>The result of invoking the <a>URL serializer</a> with <var>parsed URL</var>.
1508 <dt><a for=CSSStyleSheet>parent CSS style sheet</a>
1509 <dd>null.
1511 <dt><a for=CSSStyleSheet>owner node</a>
1512 <dd><var>node</var>.
1514 <dt><a for=CSSStyleSheet>owner CSS rule</a>
1515 <dd>null.
1517 <dt><a>media</a>
1518 <dd>The value of the <code>media</code> <a>pseudo-attribute</a>
1519 if any, or the empty string otherwise.
1521 <dt><a>title</a>
1522 <dd><var>title</var>.
1524 <dt><a>alternate flag</a>
1525 <dd>Set if the <code>alternate</code> <a>pseudo-attribute</a>
1526 value is a <a>case-sensitive</a> match for
1527 "<code>yes</code>", or unset otherwise.
1529 <dt><a>origin-clean flag</a>
1530 <dd>Set if <var>response</var> is <a>CORS-same-origin</a><!--XXX xref-->, or unset otherwise.
1531 </dl>
1533 The CSS <a>environment encoding</a> is the result of running the following steps:
1535 <ol>
1536 <li>If the element has a <code>charset</code>
1537 <a>pseudo-attribute</a>,
1538 <a>get an encoding</a> from that pseudo-attribute's value.
1539 If that succeeds, return the resulting encoding and abort these steps.
1541 <li>Otherwise, return the <a lt="encoding" for="Document">document's character encoding</a>.
1542 [[!DOM]]
1543 </ol>
1545 </ol>
1547 A style sheet referenced by an <a>xml-stylesheet processing instruction</a> using the rules in this section, in the context of
1548 the {{Document}} of an <a>XML parser</a> is said to be
1549 <a>a style sheet that is blocking scripts</a> if the <code>ProcessingInstruction</code>
1550 <a>node</a> was created by that {{Document}}'s parser, and the style sheet was
1551 enabled when the node was created by the parser, and the <a>style sheet ready</a> flag is not yet set, and, the last time the
1552 <a>event loop</a> reached step 1, the node was in that Document, and the user agent hasn't given up on that particular style sheet
1553 yet. A user agent may give up on such a style sheet at any time.
1555 ### Requirements on User Agents Implementing the HTTP Link Header ### {#requirements-on-user-agents-implementing-the-http-link-header}
1557 <!-- XXX ref, one day -->
1559 <!-- XXX deal with media param -->
1561 <p class=atrisk>For each HTTP <code>Link</code> header of which one
1562 of the link relation types is an
1563 <a>ASCII case-insensitive</a> match
1564 for "<code>stylesheet</code>" these steps
1565 must be run:
1567 <ol>
1568 <li>Let <var>title</var> be the value of the first of all the
1569 <code>title</code> parameters.
1570 If there are no such parameters it is the empty string.
1572 <li>If one of the (other) link relation types is an
1573 <a>ASCII case-insensitive</a> match for
1574 "<code>alternate</code>" and <var>title</var> is the
1575 empty string terminate these steps.
1577 <li>Let <var>input URL</var> be the value specified.
1579 Issue: Be more specific
1581 <li>Let <var>base URL</var> be the document's <a>document base URL</a>.
1583 Issue: Is there a document at this point?
1585 <li>Let <var>referrer</var> be the document's <a lt="document URL">address</a>.
1587 <li>Let <var>origin</var> be the document's <a>origin</a>.
1589 <li>Let <var>parsed URL</var> be the return value of invoking the <a>URL parser</a> with the
1590 string <var>input URL</var> and the base URL <var>base URL</var>.
1592 <li>If <var>parsed URL</var> is failure, terminate these steps.
1594 <li>Let <var>response</var> be the result of <a lt="fetch a CSS style sheet">fetching a CSS style sheet</a> with parsed URL <var>parsed URL</var>,
1595 referrer <var>referrer</var> and document being the document.
1597 Issue: What if the HTML parser hasn't decided on quirks/non-quirks yet?
1599 <li>
1600 <a>Create a CSS style sheet</a> with the following properties:
1602 <dl>
1603 <dt><a>location</a>
1604 <dd>The result of invoking the <a>URL serializer</a> with <var>parsed URL</var>.
1606 <dt><a for=CSSStyleSheet>owner node</a>
1607 <dd>null.
1609 <dt><a for=CSSStyleSheet>parent CSS style sheet</a>
1610 <dd>null.
1612 <dt><a for=CSSStyleSheet>owner CSS rule</a>
1613 <dd>null.
1615 <dt><a>media</a>
1616 <dd>The value of the first <code>media</code> parameter.
1617 <!-- XXX register media parameter? bah -->
1619 <dt><a>title</a>
1620 <dd><var>title</var>.
1622 <dt><a>alternate flag</a>
1623 <dd>Set if one of the specified link relation type for this HTTP
1624 <code>Link</code> header is an
1625 <a>ASCII case-insensitive</a> match for
1626 "<code>alternate</code>", or false otherwise.
1628 <dt><a>origin-clean flag</a>
1629 <dd>Set if <var>response</var> is <a>CORS-same-origin</a><!--XXX xref-->, or unset otherwise.
1630 </dl>
1632 </ol>
1634 A style sheet referenced by a HTTP <code>Link</code> header using the rules in this section is said to be <a>a style sheet
1635 that is blocking scripts</a> if the style sheet was enabled when created, and the <a>style sheet ready</a> flag is not yet set,
1636 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.
1638 CSS Rules {#css-rules}
1639 ----------------------
1641 A <dfn>CSS rule</dfn> is an abstract concept that
1642 denotes a rule as defined by the CSS specification. A
1643 <a for=/>CSS rule</a> is represented as an object that implements a subclass of
1644 the {{CSSRule}} interface, and which has the following
1645 associated state items:
1647 <dl dfn-for="CSSRule">
1648 <dt><dfn id=concept-css-rule-type>type</dfn>
1649 <dd>A non-negative integer associated with a particular type of rule.
1650 This item is initialized when a rule is created and cannot change.
1652 <dt><dfn id=concept-css-rule-text>text</dfn>
1653 <dd>A text representation of the rule suitable for direct use in a style sheet.
1654 This item is initialized when a rule is created and can be changed.
1656 <dt><dfn id=concept-css-rule-parent-css-rule>parent CSS rule</dfn>
1657 <dd>A reference to an enclosing <a for=/>CSS rule</a> or null.
1658 If the rule has an enclosing rule when it is created, then this item is initialized to the enclosing rule; otherwise it is null. It can be changed to
1659 null.
1661 <dt><dfn id=concept-css-rule-parent-css-style-sheet>parent CSS style sheet</dfn>
1662 <dd>A reference to a parent <a>CSS style sheet</a> or null.
1663 This item is initialized to reference an associated style sheet when the rule is created. It can be changed to null.
1665 <dt><dfn id=concept-css-rule-child-css-rules>child CSS rules</dfn>
1666 <dd>A list of child <a for=/>CSS rules</a>. The list can be mutated.
1667 </dl>
1669 In addition to the above state, each <a for=/>CSS rule</a> may be associated
1670 with other state in accordance with its <a for=CSSRule>type</a>.
1672 To <dfn>parse a CSS rule</dfn> from a string <var>string</var>, run the following steps:
1674 <ol>
1675 <li>Let <var>rule</var> be the return value of invoking <a>parse a rule</a> with <var>string</var>.
1676 <li>If <var>rule</var> is a syntax error, return <var>rule</var>.
1677 <li>Let <var>parsed rule</var> be the result of parsing <var>rule</var> according to the appropriate CSS specifications, dropping parts that are said to be
1678 ignored. If the whole style rule is dropped, return a syntax error.
1679 <li>Return <var>parsed rule</var>.
1680 </ol>
1682 To <dfn>serialize a CSS rule</dfn>, perform one of the following in accordance with the <a for=/>CSS rule</a>'s
1683 <a for=CSSRule>type</a>:
1685 <dl class="switch">
1686 <dt>{{CSSStyleRule}}
1687 <dd>
1688 The result of concatenating the following:
1689 <ol>
1690 <li>The result of performing <a>serialize a group of selectors</a> on the rule's associated selectors.
1691 <li>The string "<code> { </code>", i.e., a single SPACE (U+0020), followed by LEFT CURLY BRACKET (U+007B),
1692 followed by a single SPACE (U+0020).
1693 <li>The result of performing <a>serialize a CSS declaration block</a> on the rule's associated declarations.
1694 <li>If the rule is associated with one or more declarations, the string "<code> </code>", i.e., a single SPACE (U+0020).
1695 <li>The string "<code>}</code>", RIGHT CURLY BRACKET (U+007D).
1696 </ol>
1699 <dt>{{CSSImportRule}}
1700 <dd>
1701 The result of concatenating the following:
1702 <ol>
1703 <li>The string "<code>@import</code>" followed by a single SPACE (U+0020).
1704 <li>The result of performing <a>serialize a URL</a> on the rule's location.
1705 <li>If the rule's associated media list is not empty, a single SPACE (U+0020) followed by the
1706 result of performing <a>serialize a media query list</a> on the media list.
1707 <li>The string "<code>;</code>", i.e., SEMICOLON (U+003B).
1708 </ol>
1709 <div class="example">
1710 <pre>@import url("import.css");</pre>
1711 <pre>@import url("print.css") print;</pre>
1712 </div>
1715 <dt>{{CSSMediaRule}}
1716 <dd>Issue: ...
1718 <dt>{{CSSFontFaceRule}}
1719 <dd>Issue: ...
1721 <dt>{{CSSPageRule}}
1722 <dd>Issue: ...
1724 <dt>{{CSSNamespaceRule}}
1725 <dd>The literal string "<code>@namespace</code>", followed by a single SPACE
1726 (U+0020), followed by the
1727 <a lt="serialize an identifier">identifier escaped</a> value of the
1728 <code lt="dom-CSSNamespaceRule-prefix">prefix</code> attribute (if
1729 any), followed by a single SPACE (U+0020) if there is a prefix, followed by the
1730 <a lt="serialize a URL">URL escaped</a> value of the
1731 <code lt="dom-CSSNamespaceRule-namespaceURI">namespaceURI</code>
1732 attribute, followed the character "<code>;</code>" (U+003B).
1733 </dl>
1735 To <dfn>insert a CSS rule</dfn> <var>rule</var> in a CSS rule list <var>list</var> at index <var>index</var>, follow these steps:
1736 <ol>
1737 <li>Set <var>new rule</var> to the results of performing <a>parse a CSS rule</a>
1738 on argument <var>rule</var>.
1739 <li>If <var>new rule</var> is a syntax error, <a>throw</a>
1740 a {{SyntaxError}} exception.
1741 <li>Set <var>length</var> to the number of items in <var>list</var>.
1742 <li>If <var>index</var> is greater than <var>length</var>, then <a>throw</a>
1743 an {{IndexSizeError}} exception.
1744 <li>If <var>new rule</var> cannot be inserted into <var>list</var> at the zero-index position <var>index</var> due to constraints
1745 specified by CSS, then <a>throw</a>
1746 a {{HierarchyRequestError}} exception. [[!CSS21]]
1747 Note: For example, a CSS style sheet cannot contain an <code>@import</code> at-rule after a style rule.
1748 <li>If <var>new rule</var> is an <code>@namespace</code> at-rule, and <var>list</var> contains anything other than
1749 <code>@import</code> at-rules, and <code>@namespace</code> at-rules,
1750 <a>throw</a> an {{InvalidStateError}} exception.
1751 <li>Insert <var>new rule</var> into <var>list</var> at the zero-indexed position <var>index</var>.
1752 <li>Return <var>index</var>.
1753 </ol>
1755 To <dfn>remove a CSS rule</dfn> from a CSS rule list <var>list</var> at index <var>index</var>, follow these steps:
1756 <ol>
1757 <li>Set <var>length</var> to the number of items in <var>list</var>.
1758 <li>If <var>index</var> is greater than or equal to <var>length</var>, then <a>throw</a>
1759 an {{IndexSizeError}} exception.
1760 <li>Set <var>old rule</var> to the <var>index</var>th item in <var>list</var>.
1761 <li>If <var>old rule</var> is an <code>@namespace</code> at-rule, and <var>list</var> contains anything other than
1762 <code>@import</code> at-rules, and <code>@namespace</code> at-rules,
1763 <a>throw</a> an {{InvalidStateError}} exception.
1764 <li>Remove rule <var>old rule</var> from <var>list</var> at the zero-indexed position <var>index</var>.
1765 <li>Set <var>old rule</var>'s <a for=CSSRule>parent CSS rule</a> and
1766 <a for=CSSRule>parent CSS style sheet</a> to null.
1767 </ol>
1770 ### The {{CSSRuleList}} Interface ### {#the-cssrulelist-interface}
1772 The {{CSSRuleList}} interface represents an ordered collection of CSS style rules.
1774 <pre class=idl>
1775 [ArrayClass]
1776 interface CSSRuleList {
1777 getter CSSRule? item(unsigned long index);
1778 readonly attribute unsigned long length;
1779 };
1780 </pre>
1782 The object's <a>supported property indices</a> are the numbers in the range zero to one less than the number of
1783 {{CSSRule}} objects represented by the collection. If there are no such {{CSSRule}} objects, then there are no
1784 <a>supported property indices</a>.
1786 The <dfn method for=CSSRuleList>item(<var>index</var>)</dfn> method must return the <var>index</var>th {{CSSRule}}
1787 object in the collection. If there is no <var>index</var>th object in the collection, then the method must return null.
1789 The <dfn attribute for=CSSRuleList>length</dfn> attribute must return the number of {{CSSRule}} objects represented by the
1790 collection.
1792 ### The {{CSSRule}} Interface ### {#the-cssrule-interface}
1794 <!--
1795 //
1796 // All members defined since DOM-2 Style. The only differences are:
1797 //
1798 // 1. removal of UNKNOWN_RULE = 0 constant
1799 // 2. addition of NAMESPACE_RULE = 10 constant
1800 // 3. removal of commented raises(DOMException) on setting cssText
1801 //
1802 -->
1804 The {{CSSRule}} interface represents an abstract, base CSS style rule. Each
1805 distinct CSS style rule type is represented by a distinct interface that
1806 inherits from this interface.
1808 <pre class=idl>
1809 interface CSSRule {
1810 const unsigned short STYLE_RULE = 1;
1811 const unsigned short CHARSET_RULE = 2; // historical
1812 const unsigned short IMPORT_RULE = 3;
1813 const unsigned short MEDIA_RULE = 4;
1814 const unsigned short FONT_FACE_RULE = 5;
1815 const unsigned short PAGE_RULE = 6;
1816 const unsigned short MARGIN_RULE = 9;
1817 const unsigned short NAMESPACE_RULE = 10;
1818 readonly attribute unsigned short type;
1819 attribute DOMString cssText;
1820 readonly attribute CSSRule? parentRule;
1821 readonly attribute CSSStyleSheet? parentStyleSheet;
1822 };
1823 </pre>
1825 The <dfn attribute for=CSSRule>type</dfn> attribute must return the CSS rule type, as follows:
1827 <dl class=switch>
1828 <dt>If the object is a {{CSSStyleRule}}
1829 <dd>Return <dfn const for=CSSRule>STYLE_RULE</dfn> (numeric value 1).
1830 <dt>If the object is a {{CSSImportRule}}
1831 <dd>Return <dfn const for=CSSRule>IMPORT_RULE</dfn> (numberic value 3).
1832 <dt>If the object is a {{CSSMediaRule}}
1833 <dd>Return <dfn const for=CSSRule>MEDIA_RULE</dfn> (numeric value 4).
1834 <dt>If the object is a {{CSSFontFaceRule}}
1835 <dd>Return <dfn const for=CSSRule>FONT_FACE_RULE</dfn> (numeric value 5).
1836 <dt>If the object is a {{CSSPageRule}}
1837 <dd>Return <dfn const for=CSSRule>PAGE_RULE</dfn> (numeric value 6).
1838 <dt>If the object is a {{CSSMarginRule}}
1839 <dd>Return <dfn const for=CSSRule>MARGIN_RULE</dfn> (numeric value 9).
1840 <dt>If the object is a {{CSSNamespaceRule}}
1841 <dd>Return <dfn const for=CSSRule>NAMESPACE_RULE</dfn> (numeric value 10).
1842 <dt>Otherwise
1843 <dd>Return a value defined on the <a href="http://wiki.csswg.org/spec/cssom-constants">CSSOM Constants</a> wiki page.
1844 </dl>
1846 Note: The value 0, formerly known as <code>UNKNOWN_RULE</code>, is made
1847 obsolete by this specification. This value will not be re-allocated in the future and will remain reserved.
1849 The <dfn attribute for=CSSRule>cssText</dfn> attribute must return a <a lt="serialize a CSS rule">serialization</a> of the
1850 <a for=/>CSS rule</a>.
1851 On setting the {{CSSRule/cssText}} attribute these steps must be run:
1852 <ol>
1853 <li>Let <var>new rule</var> be the returned value of <a lt="parse a CSS rule">parsing</a> the value.
1854 <li>If <var>new rule</var> is a syntax error, terminate this algorithm.
1855 <li>If the <a for=CSSRule>type</a> of <var>new rule</var> does not match the <a for=CSSRule>type</a> of
1856 the current object
1857 <a>throw</a> an
1858 {{InvalidModificationError}} exception.
1859 <li>Replace the current object with <var>new rule</var>.
1860 </ol>
1862 The <dfn attribute for=CSSRule>parentRule</dfn> attribute must return the <a for=CSSRule>parent CSS
1863 rule</a>.
1864 Note: For example, <code>@media</code> can enclose a rule, in which case {{CSSRule/parentRule}} would
1865 be non-null; in cases where there is no enclosing rule, {{CSSRule/parentRule}} will be null.
1867 The <dfn attribute for=CSSRule>parentStyleSheet</dfn> attribute must return the
1868 <a for=CSSRule>parent CSS style sheet</a>.
1869 Note: The only circumstance where null is returned when a rule has been <a lt="remove a CSS rule">removed</a>.
1870 Note: Removing a <code>Node</code> that implements the <code>LinkStyle</code> interface from a
1871 {{Document}} instance does not (by itself) cause the <code>CSSStyleSheet</code> referenced by a <code>CSSRule</code> to be
1872 unreachable.
1875 ### The {{CSSStyleRule}} Interface ### {#the-cssstylerule-interface}
1877 <!--
1878 //
1879 // All members defined since DOM-2 Style. The only differences are:
1880 //
1881 // 1. removal of commented raises(DOMException) on setting selectorText
1882 //
1883 -->
1885 The <code>CSSStyleRule</code> interface represents a style rule.
1887 Note: CSS 2.1 calls style rule <a href="http://www.w3.org/TR/CSS21/syndata.html#rule-sets">rule sets</a>.
1889 <pre class=idl>
1890 interface CSSStyleRule : CSSRule {
1891 attribute DOMString selectorText;
1892 [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
1893 };
1894 </pre>
1896 The <dfn attribute for=CSSStyleRule>selectorText</dfn> attribute, on getting, must return the result of
1897 <a lt="serialize a group of selectors">serializing</a> the associated <a>group of selectors</a>.
1898 On setting the {{CSSStyleRule/selectorText}} attribute these steps must be run:
1899 <ol>
1900 <li>Run the <a>parse a group of selectors</a> algorithm on the given value.
1901 <li>If the algorithm returns a non-null value replace the associated <a>group of selectors</a> with the returned value.
1902 <li>Otherwise, if the algorithm returns a null value, do nothing.
1903 </ol>
1905 The <dfn attribute for=CSSStyleRule>style</dfn> attribute must return a <code>CSSStyleDeclaration</code> object for the style rule, with the
1906 following properties:
1907 <dl>
1908 <dt><a for="CSSStyleDeclaration">readonly flag</a>
1909 <dd>Unset.
1910 <dt><a for="CSSStyleDeclaration">declarations</a>
1911 <dd>The declared declarations in the rule, in <a>specified order</a>.
1912 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
1913 <dd>The <a>context object</a>.
1914 <dt><a for="CSSStyleDeclaration">owner node</a>
1915 <dd>Null.
1916 </dl>
1918 The <dfn id=concept-declarations-specified-order>specified order</dfn> for declarations is the same as specified, but with shorthand properties
1919 expanded into their longhand properties, in canonical order. If a property is specified more than once (after shorthand expansion), only the
1920 one with greatest cascading order must be represented, at the same relative position as it was specified. [[!CSS3CASCADE]]
1923 ### The {{CSSImportRule}} Interface ### {#the-cssimportrule-interface}
1925 The <code>CSSImportRule</code> interface represents an <code>@import</code> at-rule.
1927 <pre class=idl>
1928 interface CSSImportRule : CSSRule {
1929 readonly attribute DOMString href;
1930 [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
1931 [SameObject] readonly attribute CSSStyleSheet styleSheet;
1932 };
1933 </pre>
1935 The <dfn attribute for=CSSImportRule>href</dfn> attribute must return the <a for="/">URL</a> specified by
1936 the <code>@import</code> at-rule.
1937 Note: To get the resolved <a for="/">URL</a> use the {{StyleSheet/href}}
1938 attribute of the associated <a>CSS style sheet</a>.
1940 The <dfn attribute for=CSSImportRule>media</dfn> attribute must return the value of the {{StyleSheet/media}}
1941 attribute of the associated <a>CSS style sheet</a>.
1943 The <dfn attribute for=CSSImportRule>styleSheet</dfn> attribute must return the associated <a>CSS style sheet</a>.
1944 Note: If loading of the style sheet fails its <a for=CSSStyleSheet>CSS rules</a>
1945 list is simply empty, i.e., an <code>@import</code> at-rule always has an associated <a>CSS style sheet</a>.
1948 ### The {{CSSGroupingRule}} Interface ### {#the-cssgroupingrule-interface}
1950 The <code>CSSGroupingRule</code> interface represents an at-rule that contains other rules nested inside itself.
1952 <pre class=idl>
1953 interface CSSGroupingRule : CSSRule {
1954 [SameObject] readonly attribute CSSRuleList cssRules;
1955 unsigned long insertRule(DOMString rule, unsigned long index);
1956 void deleteRule(unsigned long index);
1957 };
1958 </pre>
1960 The <dfn attribute for=CSSGroupingRule>cssRules</dfn> attribute must return a <code>CSSRuleList</code> object for the
1961 <a for=CSSRule>child CSS rules</a>.
1963 The <dfn method for=CSSGroupingRule>insertRule(<var>rule</var>, <var>index</var>)</dfn> method must return the result of
1964 invoking <a>insert a CSS rule</a> <var>rule</var> into the <a for=CSSRule>child CSS rules</a> at
1965 <var>index</var>.
1967 The <dfn method for=CSSGroupingRule>deleteRule(<var>index</var>)</dfn> method must <a>remove a CSS rule</a> from the
1968 <a for=CSSRule>child CSS rules</a> at <var>index</var>.
1971 ### The {{CSSMediaRule}} Interface ### {#the-cssmediarule-interface}
1973 The <code>CSSMediaRule</code> interface represents an <code>@media</code> at-rule.
1975 <pre class=idl>
1976 interface CSSMediaRule : CSSGroupingRule {
1977 [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
1978 };
1979 </pre>
1981 The <dfn attribute for=CSSGroupingRule>media</dfn> attribute must return a <code>MediaList</code> object for the list of media queries specified
1982 with the <code>@media</code> at-rule.
1985 ### The {{CSSPageRule}} Interface ### {#the-csspagerule-interface}
1987 The <code>CSSPageRule</code> interface represents an <code>@page</code> at-rule.
1988 Issue: Need to define the rules for
1989 <dfn>parse a list of CSS page selectors</dfn> and
1990 <dfn>serialize a list of CSS page selectors</dfn>.
1992 <pre class=idl>
1993 interface CSSPageRule : CSSGroupingRule {
1994 attribute DOMString selectorText;
1995 [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
1996 };
1997 </pre>
1999 The <dfn attribute for=CSSGroupingRule>selectorText</dfn> attribute, on getting, must return the result of
2000 <a lt="serialize a list of CSS page selectors">serializing</a> the associated <a>list of CSS page selectors</a>.
2001 On setting the {{CSSPageRule/selectorText}} attribute these steps must be run:
2002 <ol>
2003 <li>Run the <a>parse a list of CSS page selectors</a> algorithm on the given value.
2004 <li>If the algorithm returns a non-null value replace the associated <a>list of CSS page selectors</a> with the returned value.
2005 <li>Otherwise, if the algorithm returns a null value, do nothing.
2006 </ol>
2008 The <dfn attribute for=CSSGroupingRule>style</dfn> attribute must return a <code>CSSStyleDeclaration</code> object for the
2009 <code>@page</code> at-rule, with the following properties:
2010 <dl>
2011 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2012 <dd>Unset.
2013 <dt><a for="CSSStyleDeclaration">declarations</a>
2014 <dd>The declared declarations in the rule, in <a>specified order</a>.
2015 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
2016 <dd>The <a>context object</a>.
2017 <dt><a for="CSSStyleDeclaration">owner node</a>
2018 <dd>Null.
2019 </dl>
2022 ### The {{CSSMarginRule}} Interface ### {#the-cssmarginrule-interface}
2024 The <code>CSSMarginRule</code> interface represents a margin at-rule (e.g. <code>@top-left</code>) in an <code>@page</code> at-rule.
2025 [[!CSS3PAGE]]
2027 <pre class=idl>
2028 interface CSSMarginRule : CSSRule {
2029 readonly attribute DOMString name;
2030 [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
2031 };
2032 </pre>
2034 The <dfn attribute for=CSSMarginRule>name</dfn> attribute must return the name of the margin at-rule. The <code>@</code> character is not
2035 included in the name. [[!CSS3SYN]]
2037 The <dfn attribute for=CSSMarginRule>style</dfn> attribute must return a <code>CSSStyleDeclaration</code> object for the
2038 margin at-rule, with the following properties:
2039 <dl>
2040 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2041 <dd>Unset.
2042 <dt><a for="CSSStyleDeclaration">declarations</a>
2043 <dd>The declared declarations in the rule, in <a>specified order</a>.
2044 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
2045 <dd>The <a>context object</a>.
2046 <dt><a for="CSSStyleDeclaration">owner node</a>
2047 <dd>Null.
2048 </dl>
2051 ### The {{CSSNamespaceRule}} Interface ### {#the-cssnamespacerule-interface}
2053 The <code>CSSNamespaceRule</code> interface represents an <code>@namespace</code> at-rule.
2055 <pre class=idl>
2056 interface CSSNamespaceRule : CSSRule {
2057 readonly attribute DOMString namespaceURI;
2058 readonly attribute DOMString prefix;
2059 };
2060 </pre>
2062 The <dfn attribute for=CSSNamespaceRule>namespaceURI</dfn> attribute must return the namespace of the
2063 <code>@namespace</code> at-rule.
2065 The <dfn attribute for=CSSNamespaceRule>prefix</dfn> attribute must return the prefix of the <code>@namespace</code> at-rule or the
2066 empty string if there is no prefix.
2069 CSS Declarations {#css-declarations}
2070 ------------------------------------
2072 A <dfn>CSS declaration</dfn> is an abstract concept that is not exposed as an object in the DOM. A <a>CSS declaration</a> has the following associated
2073 properties:
2075 <dl>
2076 <dt><dfn for="CSS declaration">property name</dfn>
2077 <dd>The property name of the declaration.
2078 <dt><dfn for="CSS declaration">value</dfn>
2079 <dd>The value of the declaration represented as a list of component values.
2080 <dt><dfn for="CSS declaration">important flag</dfn>
2081 <dd>Either set or unset. Can be changed.
2082 <dt><dfn for="CSS declaration">case-sensitive flag</dfn>
2083 <dd>Set if the <a for="CSS declaration">property name</a> is defined to be case-sensitive according to its specification,
2084 otherwise unset.
2085 </dl>
2087 CSS Declaration Blocks {#css-declaration-blocks}
2088 ------------------------------------------------
2090 A <dfn>CSS declaration block</dfn> is an ordered collection of CSS
2091 properties with their associated values, also named <a>CSS declarations</a>. In
2092 the DOM a <a>CSS declaration block</a> is a
2093 <code>CSSStyleDeclaration</code> object. A
2094 <a>CSS declaration block</a> has the following associated properties:
2096 <dl dfn-for="CSSStyleDeclaration">
2097 <dt><dfn>readonly flag</dfn>
2098 <dd>Unset if the object can be manipulated. Set if it can not be
2099 manipulated. Unless otherwise stated it is unset.
2101 <dt><dfn>declarations</dfn>
2102 <dd>The <a>CSS declarations</a> associated with the object.
2104 <dt><dfn>parent CSS rule</dfn>
2105 <dd>The <a for=/>CSS rule</a> that the <a>CSS declaration block</a> is associated with, if any, or null otherwise.
2107 <dt><dfn>owner node</dfn>
2108 <dd>The {{Element}} or {{PseudoElement}} that the <a>CSS declaration block</a> is associated with, if any, or
2109 null otherwise.
2110 </dl>
2112 To <dfn>parse a CSS declaration block</dfn> from a string <var>string</var>, follow these steps:
2114 <ol>
2115 <li>Let <var>declarations</var> be the return value of invoking <a>parse a list of declarations</a> with <var>string</var>.
2116 <li>Let <var>parsed declarations</var> be a new empty list.
2117 <li>For each item <var>declaration</var> in <var>declarations</var>, follow these substeps:
2118 <ol>
2119 <li>Let <var>parsed declaration</var> be the result of parsing <var>declaration</var> according to the appropriate CSS specifications, dropping parts that
2120 are said to be ignored. If the whole declaration is dropped, let <var>parsed declaration</var> be null.
2121 <li>If <var>parsed declaration</var> is not null, append it to <var>parsed declarations</var>.
2122 </ol>
2123 <li>Return <var>parsed declarations</var>.
2124 </ol>
2126 To <dfn>serialize a CSS declaration</dfn> with property name <var>property</var>, value <var>value</var> and optionally an <i>important</i> flag set, follow
2127 these steps:
2129 <ol>
2130 <li>Let <var>s</var> be the empty string.
2131 <li>Append <var>property</var> to <var>s</var>.
2132 <li>Append "<code>: </code>" (U+003A U+0020) to <var>s</var>.
2133 <li>Append <var>value</var> to <var>s</var>.
2134 <li>If the <i>important</i> flag is set, append "<code> !important</code>" (U+0020 U+0021 U+0069 U+006D U+0070 U+006F U+0072 U+0074 U+0061 U+006E
2135 U+0074) to <var>s</var>.
2136 <li>Append "<code>;</code>" (U+003B) to <var>s</var>.
2137 <li>Return <var>s</var>.
2138 </ol>
2140 To <dfn>serialize a CSS declaration block</dfn> <var>declaration block</var> means to run the steps below:
2142 <ol>
2143 <li>Let <var>list</var> be an empty array.
2144 <li>Let <var>already serialized</var> be an empty array.
2145 <li><i>Declaration loop</i>: For each <a>CSS declaration</a> <var>declaration</var> in <var>declaration block</var>'s
2146 <a for="CSSStyleDeclaration">declarations</a>, follow these substeps:
2147 <ol>
2148 <li>Let <var>property</var> be <var>declaration</var>'s <a for="CSS declaration">property name</a>.
2149 <li>If <var>property</var> is in <var>already serialized</var>, continue with the steps labeled <i>declaration loop</i>.
2150 <li>If <var>property</var> maps to one or more shorthand properties, let <var>shorthands</var> be an array of those shorthand properties, in
2151 <a>preferred order</a>, and follow these substeps:
2152 <ol>
2153 <li>Let <var>longhands</var> be an array consisting of all <a>CSS declarations</a> in <var>declaration block</var>'s
2154 <a for="CSSStyleDeclaration">declarations</a> that that are not in <var>already serialized</var> and have a
2155 <a for="CSS declaration">property name</a> that
2156 maps to one of the shorthand properties in <var>shorthands</var>.
2157 <li><i>Shorthand loop</i>: For each <var>shorthand</var> in <var>shorthands</var>, follow these substeps:
2158 <ol>
2159 <li>If all properties that map to <var>shorthand</var> are not present in <var>longhands</var>, continue with the steps labeled <i>shorthand loop</i>.
2160 <li>Let <var>current longhands</var> be an empty array.
2161 <li>Append all <a>CSS declarations</a> in <var>longhands</var> have a
2162 <a for="CSS declaration">property name</a> that maps to <var>shorthand</var> to <var>current longhands</var>.
2163 <li>If there is one or more <a>CSS declarations</a> in <var>current longhands</var> have their
2164 <a for="CSS declaration">important flag</a> set and one or more with it unset, continue with
2165 the steps labeled <i>shorthand loop</i>.
2166 <li>Let <var>value</var> be the result of invoking <a>serialize a CSS value</a> of <var>current longhands</var>.
2167 <li>If <var>value</var> is the empty string, continue with the steps labeled <i>shorthand loop</i>.
2168 <li>Let <var>serialized declaration</var> be the result of invoking <a>serialize a CSS declaration</a> with property name
2169 <var>shorthand</var>, value <var>value</var>, and the <i>important</i> flag set if the <a>CSS declarations</a> in
2170 <var>current longhands</var> have their <a for="CSS declaration">important flag</a> set.
2171 <li>Append <var>serialized declaration</var> to <var>list</var>.
2172 <li>Append the property names of all items of <var>current longhands</var> to <var>already serialized</var>.
2173 <li>Remove the items present in <var>current longhands</var> from <var>longhands</var>.
2174 </ol>
2175 </ol>
2176 <li>If <var>property</var> is in <var>already serialized</var>, continue with the steps labeled <i>declaration loop</i>.
2177 <li>Let <var>value</var> be the result of invoking <a>serialize a CSS value</a> of <var>declaration</var>.
2178 <li>Let <var>serialized declaration</var> be the result of invoking <a>serialize a CSS declaration</a> with property name <var>property</var>, value
2179 <var>value</var>, and the <i>important</i> flag set if <var>declaration</var> has its <a for="CSS declaration">important
2180 flag</a> set.
2181 <li>Append <var>serialized declaration</var> to <var>list</var>.
2182 <li>Append <var>property</var> to <var>already serialized</var>.
2183 </ol>
2184 <li>Return <var>list</var> joined with "<code> </code>" (U+0020).
2185 </ol>
2187 Note: The serialization of an empty CSS declaration block is the empty string.
2189 Note: The serialization of a non-empty CSS declaration block does not include any surrounding whitespace, i.e., no whitepsace appears
2190 before the first property name and no whitespace appears after the final semicolon delimiter that follows the last property value.
2192 The <dfn id=concept-shorthands-preferred-order>preferred order</dfn> of a list of shorthand properties <var>shorthands</var> is as follows:
2194 <ol>
2195 <li>Order <var>shorthands</var> lexicographically.
2196 <li>Move all items in <var>shorthands</var> that begin with "<code>-</code>" (U+002D) last in the list, retaining their relative order.
2197 <li>Move all items in <var>shorthands</var> that begin with "<code>-</code>" (U+002D) but do not begin with "<code>-webkit-</code>" last in the
2198 list, retaining their relative order.
2199 <li>Order <var>shorthands</var> by the number of longhand properties that map to it, with the greatest number first.
2200 </ol>
2202 ### The {{CSSStyleDeclaration}} Interface ### {#the-cssstyledeclaration-interface}
2204 The <code>CSSStyleDeclaration</code> interface represents a <a>CSS declaration block</a>, including its underlying state, where this
2205 underlying state depends upon the source of the <code>CSSStyleDeclaration</Code> instance.
2207 <!--
2208 //
2209 // All members defined since DOM-2 Style. The only differences are:
2210 //
2211 // 1. removal of commented raises(DOMException) on setting cssText
2212 // 2. removal of raises(DOMException) on {set,remove}Property
2213 // 3. removal of getPropertyCSSValue() method
2214 //
2215 -->
2217 <pre class=idl>
2218 interface CSSStyleDeclaration {
2219 attribute DOMString cssText;
2220 readonly attribute unsigned long length;
2221 getter DOMString item(unsigned long index);
2222 DOMString getPropertyValue(DOMString property);
2223 DOMString getPropertyPriority(DOMString property);
2224 void setProperty(DOMString property, [TreatNullAs=EmptyString] DOMString value, [TreatNullAs=EmptyString] optional DOMString priority = "");
2225 void setPropertyValue(DOMString property, [TreatNullAs=EmptyString] DOMString value);
2226 void setPropertyPriority(DOMString property, [TreatNullAs=EmptyString] DOMString priority);
2227 DOMString removeProperty(DOMString property);
2228 readonly attribute CSSRule? parentRule;
2229 [TreatNullAs=EmptyString] attribute DOMString cssFloat;
2230 };
2231 </pre>
2233 The object's <a>supported property indices</a> are the numbers in the range zero to one less than the number of
2234 <a>CSS declarations</a> in the <a for="CSSStyleDeclaration">declarations</a>. If there are no such
2235 <a>CSS declarations</a>, then there are no <a>supported property indices</a>.
2237 The <dfn attribute for=CSSStyleDeclaration>cssText</dfn> attribute must return the result of
2238 <a lt="serialize a CSS declaration block">serializing</a> the <a for="CSSStyleDeclaration">declarations</a>.
2239 Setting the {{CSSStyleDeclaration/cssText}} attribute must run these steps:
2240 <ol>
2241 <li>If the <a for="CSSStyleDeclaration">readonly flag</a> is set, <a>throw</a>
2242 a {{NoModificationAllowedError}} exception and terminate these steps.
2243 <li>Empty the <a for="CSSStyleDeclaration">declarations</a>.
2244 <li><a lt="Parse a CSS declaration block">Parse</a> the given value and, if the return value is not the empty list, insert the items in the list
2245 into the <a for="CSSStyleDeclaration">declarations</a>, in <a>specified order</a>.
2246 </ol>
2248 The <dfn attribute for=CSSStyleDeclaration>length</dfn> attribute must return the number of <a lt="CSS declaration">CSS
2249 declarations</a> in the <a for="CSSStyleDeclaration">declarations</a>.
2251 The <dfn method for=CSSStyleDeclaration>item(<var>index</var>)</dfn> method must return the
2252 <a for="CSS declaration">property name</a> of the <a>CSS declaration</a> at position <var>index</var>.
2254 The <dfn method for=CSSStyleDeclaration>getPropertyValue(<var>property</var>)</dfn> method must run these steps:
2255 <ol>
2256 <li>Let <var>property</var> be <var>property</var> <a>converted to ASCII lowercase</a>.
2257 <li>If <var>property</var> is a shorthand property, then follow these substeps:
2258 <ol>
2259 <li>Let <var>list</var> be a new empty array.
2260 <li>For each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical order, follow these substeps:
2261 <ol>
2262 <li>If <var>longhand</var> is a <a>case-sensitive</a> match for a <a for="CSS declaration">property
2263 name</a> of a <a>CSS declaration</a> in the <a for="CSSStyleDeclaration">declarations</a>, let <var>declaration</var>
2264 be that <a>CSS declaration</a>, or null otherwise.
2265 <li>If <var>declaration</var> is null, return the empty string and terminate these steps.
2266 <li>Append the <var>declaration</var> to <var>list</var>.
2267 </ol>
2268 <li>Return the <a lt="serialize a CSS value">serialization</a> of <var>list</var> and terminate these steps.
2269 </ol>
2270 <li>If <var>property</var> is a <a>case-sensitive</a>
2271 match for a <a for="CSS declaration">property name</a> of a <a>CSS declaration</a> in the
2272 <a for="CSSStyleDeclaration">declarations</a>, return the result of invoking
2273 <a>serialize a CSS value</a> of that declaration and terminate these steps.
2274 <li>Return the empty string.
2275 </ol>
2277 The <dfn method for=CSSStyleDeclaration>getPropertyPriority(<var>property</var>)</dfn> method must run these steps:
2278 <ol>
2279 <li>Let <var>property</var> be <var>property</var> <a>converted to ASCII lowercase</a>.
2280 <li>If <var>property</var> is a shorthand property, follow these substeps:
2281 <ol>
2282 <li>Let <var>list</var> be a new array.
2283 <li>For each longhand property <var>longhand</var> that <var>property</var> maps to, append the result of invoking
2284 {{CSSStyleDeclaration/getPropertyPriority()}} with <var>longhand</var> as argument to <var>list</var>.
2285 <li>If all items in <var>list</var> are the string "<code>important</code>", return the string "<code>important</code>" and terminate these
2286 steps.
2287 </ol>
2288 <li>Otherwise, follow these substeps:
2289 <ol>
2290 <li>If <var>property</var> is a
2291 <a>case-sensitive</a> match for a <a for="CSS declaration">property name</a> of a <a>CSS
2292 declaration</a> in the <a for="CSSStyleDeclaration">declarations</a> that has the
2293 <a for="CSS declaration">important flag</a> set, return the string "<code>important</code>".
2294 </ol>
2295 <li>Return the empty string.
2296 </ol>
2297 <div class=example>E.g. for <code>background-color:lime !IMPORTANT</code> the return
2298 value would be "<code>important</code>".</div>
2300 The <dfn method for=CSSStyleDeclaration>setProperty(<var>property</var>, <var>value</var>, <var>priority</var>)</dfn> method must run these steps:
2301 <ol>
2302 <li>If the <a for="CSSStyleDeclaration">readonly flag</a> is set, <a>throw</a>
2303 a {{NoModificationAllowedError}} exception and terminate these steps.
2304 <li>Let <var>property</var> be <var>property</var> <a>converted to ASCII lowercase</a>.
2305 <li>If <var>property</var> is not a <a>case-sensitive</a> match for a <a>supported CSS property</a>, terminate this
2306 algorithm.
2307 <li>If <var>value</var> is the empty string, invoke {{CSSStyleDeclaration/removeProperty()}}
2308 with <var>property</var> as argument and terminate this algorithm.
2309 <li>If <var>priority</var> is not the empty string and is not an <a>ASCII case-insensitive</a> match for the string
2310 "<code>important</code>", terminate this algorithm.
2311 <li>
2312 Let <var>component value list</var> be the result of <a lt="parse a CSS value">parsing</a> <var>value</var> for property <var>property</var>.
2313 Note: <var>value</var> can not include "<code>!important</code>".
2315 <li>If <var>component value list</var> is null terminate these steps.
2316 <li>If <var>property</var> is a shorthand property, then for each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical
2317 order, <a lt="set a CSS declaration">set the CSS declaration</a> <var>longhand</var> with the appropriate value(s) from <var>component value
2318 list</var>, with the <i>important</i> flag set if <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
2319 <a for="CSSStyleDeclaration">declarations</a>.
2320 <li>Otherwise, <a lt="set a CSS declaration">set the CSS declaration</a> <var>property</var> with value <var>component value list</var>, with
2321 the <i>important</i> flag set if <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
2322 <a for="CSSStyleDeclaration">declarations</a>.
2323 </ol>
2325 To <dfn>set a CSS declaration</dfn> <var>property</var> with a value <var>component value list</var> and optionally with an <i>important</i> flag set, in
2326 a list of declarations <var>declarations</var>, follow these steps:
2328 <ol>
2329 <li>If <var>property</var> is a <a>case-sensitive</a> match for a <a for="CSS declaration">property
2330 name</a> of a <a>CSS declaration</a> in <var>declarations</var>, let <var>declaration</var> be that <a>CSS declaration</a>.
2331 <li>Otherwise, append a new <a>CSS declaration</a> with the <a for="CSS declaration">property name</a> <var>property</var>
2332 to <var>declarations</var> and let <var>declaration</var> be that <a>CSS declaration</a>.
2333 <li>Set <var>declaration</var>'s <a for="CSS declaration">value</a> to <var>component value list</var>.
2334 <li>If the <i>important</i> flag is set, set <var>declaration</var>'s <a for="CSS declaration">important flag</a>.
2335 Otherwise, unset <var>declaration</var>'s <a for="CSS declaration">important flag</a>.
2336 </ol>
2338 The <dfn method for=CSSStyleDeclaration>setPropertyValue(<var>property</var>, <var>value</var>)</dfn> method must run these
2339 steps:
2340 <ol>
2341 <li>If the <a for="CSSStyleDeclaration">readonly flag</a> is set, <a>throw</a>
2342 a {{NoModificationAllowedError}} exception and terminate these steps.
2343 <li>Let <var>property</var> be <var>property</var> <a>converted to ASCII lowercase</a>.
2344 <li>If <var>property</var> is not a <a>case-sensitive</a> match for a <a>supported CSS property</a>, terminate this
2345 algorithm.
2346 <li>If <var>value</var> is the empty string, invoke {{CSSStyleDeclaration/removeProperty()}}
2347 with <var>property</var> as argument and terminate this algorithm.
2348 <li>
2349 Let <var>component value list</var> be the result of <a lt="parse a CSS value">parsing</a> <var>value</var> for property <var>property</var>.
2350 Note: <var>value</var> can not include "<code>!important</code>".
2352 <li>If <var>component value list</var> is null terminate these steps.
2353 <li>If <var>property</var> is a shorthand property, then for each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical
2354 order, <a lt="set a CSS declaration value">set the CSS declaration value</a> <var>longhand</var> to the appropriate value(s) from <var>component
2355 value list</var>, and with the list of declarations being the <a for="CSSStyleDeclaration">declarations</a>.
2356 <li>Otherwise, <a lt="set a CSS declaration value">set the CSS declaration value</a> <var>property</var> to the value <var>component value
2357 list</var>, and with the list of declarations being the <a for="CSSStyleDeclaration">declarations</a>.
2358 </ol>
2360 To <dfn>set a CSS declaration value</dfn> to a value <var>component value list</var> in a list of declarations <var>declarations</var>, follow these steps:
2362 <ol>
2363 <li>If <var>property</var> is a <a>case-sensitive</a> match for a <a for="CSS declaration">property
2364 name</a> of a <a>CSS declaration</a> in <var>declarations</var>, let <var>declaration</var> be that <a>CSS declaration</a>.
2365 <li>Otherwise, append a new <a>CSS declaration</a> with the <a for="CSS declaration">property name</a> <var>property</var>
2366 to <var>declarations</var> and let <var>declaration</var> be that <a>CSS declaration</a>.
2367 <li>Set <var>declaration</var>'s <a for="CSS declaration">value</a> to <var>component value list</var>.
2368 </ol>
2370 The <dfn method for=CSSStyleDeclaration>setPropertyPriority(<var>property</var>, <var>priority</var>)</dfn> method must run
2371 these steps:
2373 <ol>
2374 <li>If the <a for="CSSStyleDeclaration">readonly flag</a> is set, <a>throw</a>
2375 a {{NoModificationAllowedError}} exception and terminate these steps.
2376 <li>Let <var>property</var> be <var>property</var> <a>converted to ASCII lowercase</a>.
2377 <li>If <var>property</var> is not a <a>case-sensitive</a> match for a <a>supported CSS property</a>, terminate this
2378 algorithm.
2379 <li>If <var>priority</var> is not the empty string and is not an <a>ASCII case-insensitive</a> match for the string
2380 "<code>important</code>", terminate this algorithm.
2381 <li>If <var>property</var> is a shorthand property, then for each longhand property <var>longhand</var> that <var>property</var> maps to, in canonical
2382 order, <a lt="set a CSS declaration priority">set the CSS declaration priority</a> <var>longhand</var> with the <i>important</i> flag set if
2383 <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
2384 <a for="CSSStyleDeclaration">declarations</a>.
2385 <li>Otherwise, <a lt="set a CSS declaration priority">set the CSS declaration priority</a> <var>property</var> with the <i>important</i> flag set
2386 if <var>priority</var> is not the empty string, and unset otherwise, and with the list of declarations being the
2387 <a for="CSSStyleDeclaration">declarations</a>.
2388 </ol>
2390 To <dfn>set a CSS declaration priority</dfn> <var>property</var> optionally with an <i>important</i> flag set, in a list of declarations
2391 <var>declarations</var>, follow these steps:
2393 <ol>
2394 <li>If <var>property</var> is a <a>case-sensitive</a> match for a <a for="CSS declaration">property
2395 name</a> of a <a>CSS declaration</a> in <var>declarations</var>, let <var>declaration</var> be that <a>CSS declaration</a>.
2396 <li>Otherwise, terminate these steps.
2397 <li>If the <i>important</i> flag is set, set <var>declaration</var>'s <a for="CSS declaration">important flag</a>. Otherwise,
2398 unset <var>declaration</var>'s <a for="CSS declaration">important flag</a>.
2399 </ol>
2401 The <dfn method for=CSSStyleDeclaration>removeProperty(<var>property</var>)</dfn> method must run these steps:
2402 <ol>
2403 <li>If the <a for="CSSStyleDeclaration">readonly flag</a> is set, <a>throw</a>
2404 a {{NoModificationAllowedError}} exception and terminate these steps.
2405 <li>Let <var>property</var> be <var>property</var> <a>converted to ASCII lowercase</a>.
2406 <li>Let <var>value</var> be the return value of invoking {{CSSStyleDeclaration/getPropertyValue()}}
2407 with <var>property</var> as argument.
2408 <li>If <var>property</var> is a shorthand property, for each longhand property <var>longhand</var> that <var>property</var> maps to, invoke
2409 {{CSSStyleDeclaration/removeProperty()}} with <var>longhand</var> as argument.
2410 <li>Otherwise, if <var>property</var> is a <a>case-sensitive</a> match for a
2411 <a for="CSS declaration">property name</a> of a <a>CSS declaration</a> in the
2412 <a for="CSSStyleDeclaration">declarations</a>, remove that <a>CSS declaration</a>.
2413 <li>Return <var>value</var>.
2414 </ol>
2416 The <dfn attribute for=CSSStyleDeclaration>parentRule</dfn> attribute must return the
2417 <a for="CSSStyleDeclaration">parent CSS rule</a>.
2419 The <dfn attribute for=CSSStyleDeclaration>cssFloat</dfn>
2420 attribute, on getting, must return the result of invoking
2421 {{CSSStyleDeclaration/getPropertyValue()}} with
2422 <code>float</code> as argument. On setting, the attribute must invoke
2423 {{CSSStyleDeclaration/setProperty()}} with
2424 <code>float</code> as first argument, as second argument the given value, and no third argument.
2425 Any exceptions thrown must be re-thrown.
2427 For each CSS property <var>property</var> that is a <a>supported CSS property</a>,
2428 the following partial interface applies where <var>camel-cased attribute</var>
2429 is obtained by running the <a>CSS property to IDL attribute</a> algorithm for
2430 <var>property</var>.
2432 <pre class="idl extract">
2433 partial interface CSSStyleDeclaration {
2434 [TreatNullAs=EmptyString] attribute DOMString _<var>camel_cased_attribute</var>;
2435 };
2436 </pre>
2438 The <dfn attribute for=CSSStyleDeclaration><var>camel-cased attribute</var></dfn> attribute, on getting, must return the
2439 result of invoking {{CSSStyleDeclaration/getPropertyValue()}} with the
2440 argument being the result of running the <a>IDL attribute to CSS property</a>
2441 algorithm for <var>camel-cased attribute</var>.
2443 Setting the <code attribute for=CSSStyleDeclaration><var>camel-cased attribute</var></code> attribute must invoke
2444 {{CSSStyleDeclaration/setProperty()}} with the
2445 first argument being the result of running the <a>IDL attribute to CSS property</a>
2446 algorithm for <var>camel-cased attribute</var>, as second argument the given value, and no third argument. Any
2447 exceptions thrown must be re-thrown.
2449 <div class=example>For example, for the 'font-size' property there would be a <code>fontSize</code> IDL attribute.</div>
2451 For each CSS property <var>property</var> that is a <a>supported CSS property</a> and that begins
2452 with the string <code>-webkit-</code>, the following partial interface applies where
2453 <var>webkit-cased attribute</var> is obtained by running the <a>CSS property to IDL attribute</a>
2454 algorithm for <var>property</var>, with the <i>lowercase first</i> flag set.
2456 <pre class="idl extract">
2457 partial interface CSSStyleDeclaration {
2458 [TreatNullAs=EmptyString] attribute DOMString _<var>webkit_cased_attribute</var>;
2459 };
2460 </pre>
2462 The <dfn attribute for=CSSStyleDeclaration><var>webkit-cased attribute</var></dfn> attribute, on
2463 getting, must return the result of invoking {{CSSStyleDeclaration/getPropertyValue()}} with the
2464 argument being the result of running the <a>IDL attribute to CSS property</a> algorithm for
2465 <var>webkit-cased attribute</var>, with the <i>dash prefix</i> flag set.
2467 Setting the <code attribute for=CSSStyleDeclaration><var>webkit-cased attribute</var></code>
2468 attribute must invoke {{CSSStyleDeclaration/setProperty()}} with the first argument being the result
2469 of running the <a>IDL attribute to CSS property</a> algorithm for <var>webkit-cased attribute</var>,
2470 with the <i>dash prefix</i> flag set, as second argument the given value, and no third argument.
2471 Any exceptions thrown must be re-thrown.
2473 <div class=example>For example, if the user agent supports the '-webkit-transform' property, there
2474 would be a <code>webkitTransform</code> IDL attribute. There would also be a
2475 <code>WebkitTransform</code> IDL attribute because of the rules for camel-cased attributes.</div>
2477 For each CSS property <var>property</var> that is a <a>supported CSS property</a>,
2478 except for properties that have no "<code>-</code>" (U+002D) in the property name,
2479 the following partial interface applies where <var>dashed attribute</var> is <var>property</var>.
2481 <pre class="idl">
2482 partial interface CSSStyleDeclaration {
2483 [TreatNullAs=EmptyString] attribute DOMString _<var>dashed_attribute</var>;
2484 };
2485 </pre>
2487 The <dfn attribute for=CSSStyleDeclaration><var>dashed attribute</var></dfn> attribute, on getting, must return the
2488 result of invoking {{CSSStyleDeclaration/getPropertyValue()}} with the
2489 argument being <var>dashed attribute</var>.
2491 Setting the <code attribute for=CSSStyleDeclaration><var>dashed attribute</var></code> attribute must invoke
2492 {{CSSStyleDeclaration/setProperty()}} with the
2493 first argument being <var>dashed attribute</var>, as second argument the given value, and no third argument. Any
2494 exceptions thrown must be re-thrown.
2496 <div class=example>
2497 For example, for the 'font-size' property there would be a <code>font-size</code> IDL attribute. In JavaScript, the property can be accessed as
2498 follows, assuming <var>element</var> is an <a lt="HTML elements">HTML element</a>:
2499 <pre><var>element</var>.style['font-size'];</pre>
2500 </div>
2502 The <dfn>CSS property to IDL attribute</dfn> algorithm for <var>property</var>, optionally with a
2503 <i>lowercase first</i> flag set, is as follows:
2505 <ol>
2506 <li>Let <var>output</var> be the empty string.
2508 <li>Let <var>uppercase next</var> be unset.
2510 <li>If the <i>lowercase first</i> flag is set, remove the first character from <var>property</var>.
2512 <li>For each character <var>c</var> in <var>property</var>:
2514 <ol>
2515 <li>If <var>c</var> is "<code>-</code>" (U+002D), let <var>uppercase next</var> be set.
2517 <li>Otherwise, if <var>uppercase next</var> is set, let <var>uppercase next</var> be unset and append <var>c</var>
2518 <a>converted to ASCII uppercase</a> to <var>output</var>.
2520 <li>Otherwise, append <var>c</var> to <var>output</var>.
2521 </ol>
2523 <li>Return <var>output</var>.
2524 </ol>
2526 The <dfn>IDL attribute to CSS property</dfn> algorithm for <var>attribute</var>, optionally with a
2527 <i>dash prefix</i> flag set, is as follows:
2529 <ol>
2530 <li>Let <var>output</var> be the empty string.
2532 <li>If the <i>dash first</i> flag is set, append "<code>-</code>" (U+002D) to <var>output</var>.
2534 <li>For each character <var>c</var> in <var>attribute</var>:
2536 <ol>
2537 <li>If <var>c</var> is in the range U+0041 to U+005A (ASCII uppercase), append "<code>-</code>" (U+002D) followed by <var>c</var>
2538 <a>converted to ASCII lowercase</a> to <var>output</var>.
2540 <li>Otherwise, append <var>c</var> to <var>output</var>.
2541 </ol>
2543 <li>Return <var>output</var>.
2544 </ol>
2547 CSS Values {#css-values}
2548 ------------------------
2551 ### Parsing CSS Values ### {#parsing-css-values}
2553 To <dfn>parse a CSS value</dfn> <var>value</var> for a given
2554 <var>property</var> means to follow these steps:
2556 <ol>
2557 <li>Let <var>list</var> be the value returned by invoking <a>parse a list of component values</a> from <var>value</var>.
2558 <li>Match <var>list</var> against the grammar for the property <var>property</var> in the CSS specification.
2559 <li>If the above step failed, return null.
2560 <li>Return <var>list</var>.
2561 </ol>
2563 Note: "<code>!important</code>" declarations are not
2564 part of the property value space and will therefore cause
2565 <a>parse a CSS value</a> to return null.
2569 ### Serializing CSS Values ### {#serializing-css-values}
2571 <!-- based on http://damowmow.com/playground/canon.txt -->
2573 To <dfn>serialize a CSS value</dfn> of a <a>CSS declaration</a> <var>declaration</var> or a list of longhand <a lt="CSS declaration">CSS
2574 declarations</a> <var>list</var>, follow these rules:
2576 <ol>
2577 <li>If this algorithm is invoked with a list <var>list</var>, follow these substeps:
2578 <ol>
2579 <li>Let <var>shorthand</var> be the shorthand property that exactly maps to all the longhand properties in <var>list</var>. If there are multiple such
2580 shorthand properties, use the first in <a>preferred order</a>.
2581 <li>If <var>shorthand</var> cannot represent the values of <var>list</var> in its grammar, return the empty string and terminate these steps.
2582 <li>Let <var>trimmed list</var> be a new empty array.
2583 <li>For each <a>CSS declaration</a> <var>declaration</var> in <var>list</var>, if <var>declaration</var>'s
2584 <a for="CSS declaration">value</a> is not the initial value, or if
2585 <var>declaration</var> is a required component of the <var>shorthand</var> property, append <var>declaration</var> to <var>trimmed list</var>.
2586 <li>If <var>trimmed list</var> is empty, append the value of the first item in <var>list</var> to <var>trimmed list</var>.
2587 <li>Let <var>values</var> be a new empty array.
2588 <li>For each <a>CSS declaration</a> <var>declaration</var> in <var>trimmed list</var>, invoke <a>serialize a CSS value</a> of
2589 <var>declaration</var>, and append the result to <var>values</var>.
2590 <li>Return the result of joining <var>values</var> as appropriate according to the grammar of <var>shorthand</var> and terminate these steps.
2591 </ol>
2592 <li>Let <var>values</var> be a new empty array.
2593 <li>Append the result of invoking <a>serialize a CSS component value</a> of <var>declaration</var>'s
2594 <a for="CSS declaration">value</a> to <var>values</var>.
2595 <li>If the grammar of the <a for="CSS declaration">property name</a> of <var>declaration</var> is defined to be
2596 whitespace-separated, return the result of invoking <a>serialize a whitespace-separated list</a> of <var>values</var> and terminate these steps.
2597 <li>If the grammar of the <a for="CSS declaration">property name</a> of <var>declaration</var> is defined to be comma-separated,
2598 return the result of invoking <a>serialize a comma-separated list</a> of <var>values</var>.
2599 </ol>
2601 To
2602 <dfn>serialize a CSS component value</dfn>
2603 depends on the component, as follows:
2605 <dl class="switch">
2606 <dt>keyword
2607 <dd>The keyword
2608 <a>converted to ASCII lowercase</a>.
2610 <dt><angle>
2611 <dd>The <number> component serialized as per <number> followed by the unit in canonical form as defined in its respective specification.
2613 <dt><color>
2614 <dd>
2615 If <color> is a component of a resolved or computed value, then
2616 return the color using the <code>rgb()</code> or <code>rgba()</code> functional
2617 notation as follows:
2618 <ol>
2619 <li>If the alpha component of the color is equal to one, then return the serialization of the
2620 <code>rgb()</code> functional equivalent of the opaque color.
2621 <li>If the alpha component of the color is not equal to one, then return the serialization of the
2622 <code>rgba()</code> functional equivalent of the non-opaque color.
2623 </ol>
2624 The serialization of the <code>rgb()</code> functional equivalent is the concatenation of the following:
2625 <ol>
2626 <li>The string "<code>rgb(</code>".
2627 <li>The shortest base-ten integer serialization of the color's red component.
2628 <li>The string "<code>, </code>".
2629 <li>The shortest base-ten serialization of the color's green component.
2630 <li>The string "<code>, </code>".
2631 <li>The shortest base-ten serialization of the color's blue component.
2632 <li>The string "<code>)</code>".
2633 </ol>
2634 The serialization of the <code>rgba()</code> functional equivalent is the concatenation of the following:
2635 <ol>
2636 <li>The string "<code>rgba(</code>".
2637 <li>The shortest base-ten serialization of the color's red component.
2638 <li>The string "<code>, </code>".
2639 <li>The shortest base-ten serialization of the color's green component.
2640 <li>The string "<code>, </code>".
2641 <li>The shortest base-ten serialization of the color's blue component.
2642 <li>The string "<code>, </code>".
2643 <li>The serialization of the color's alpha component as an <alphavalue>.
2644 <li>The string "<code>)</code>".
2645 </ol>
2647 In the above rules, the string "<code>, </code>" denotes a COMMA (U+002C) followed by a single SPACE (U+0020).
2649 If <color> is a component of a specified value, then
2650 return the color as follows:
2651 <ol>
2652 <li>If the color was explicitly specified by the author, then return the original, author specified color value.
2653 <li>Otherwise, return the value that would be returned if the color were a component of a computed value.
2654 </ol>
2655 Issue: Should author specified values be normalized for case? Or should original case be preserved?
2657 <!--
2658 <dt>It is a system color
2660 <dd>See below (you use the representation given in the specification that
2661 defines the keyword).
2663 <dt>Alpha component is equal to 1.0
2665 <dd>The color is an uppercase six-digit hexadecimal value, prefixed with a
2666 <code>#</code> character (U+0023 NUMBER SIGN), with the first two digits
2667 representing the red component, the next two digits representing the green
2668 component, and the last two digits representing the blue component, the
2669 digits being in the range 0-9 A-F (U+0030 to U+0039 and U+0041 to
2670 U+0046).
2672 <dt>Alpha component is less than 1.0
2674 <dd>The color is in the CSS <code>rgba()</code> functional-notation format:
2675 the literal string <code>rgba</code> (U+0072 U+0067 U+0062 U+0061) followed
2676 by a U+0028 LEFT PARENTHESIS, a <a>color component integer</a>
2677 representing the red component, a <a>color component separator</a>, a
2678 <a>color component integer</a> for the green component, a <a>color
2679 component separator</a>, a <a>color component integer</a> for the
2680 blue component, another <a>color component separator</a> a U+0030
2681 DIGIT ZERO, a U+002E FULL STOP (representing the decimal point), one or
2682 more digits in the range 0-9 (U+0030 to U+0039) representing the fractional
2683 part of the alpha value, and finally a U+0029 RIGHT PARENTHESIS.
2685 <dt>The keyword <code>transparent</code> is used
2687 <dd>The color is <code>rgba(0, 0, 0, 0)</code>.
2688 -->
2690 <dt><alphavalue>
2691 <dd>
2692 If the value is internally represented as an integer between 0 and 255 inclusive (i.e. 8-bit unsigned integer),
2693 follow these steps:
2695 <ol>
2696 <li>Let <var>alpha</var> be the given integer.
2697 <li>If there exists an integer between 0 and 100 inclusive that,
2698 when multiplied with 2.55 and rounded to the closest integer (rounding up if two values are equally close), equals <var>alpha</var>,
2699 let <var>rounded</var> be that integer divided by 100.
2700 <li>Otherwise, let <var>rounded</var> be <var>alpha</var> divided by 0.255 and rounded to the closest integer (rounding up if two values are equally close),
2701 divided by 1000.
2702 <li>Return the result of serializing <var>rounded</var> as a <number>.
2703 </ol>
2705 Otherwise, return the result of serializing the given value as a <number>.
2707 <dt><counter>
2708 <dd>
2709 The return value of the following algorithm:
2710 <ol>
2711 <li>Let <var>s</var> be the empty string.
2712 <li>If <counter> has three CSS component values append the string
2713 "<code>counters(</code>" to <var>s</var>.
2714 <li>If <counter> has two CSS component values append the string
2715 "<code>counter(</code>" to <var>s</var>.
2716 <li>Let <var>list</var> be a list of CSS component values belonging to <counter>, omitting the last CSS component value if it is "decimal".
2717 <li>Let each item in <var>list</var> be the result of invoking <a>serialize a CSS component value</a> on that item.
2718 <li>Append the result of invoking <a>serialize a comma-separated list</a> on <var>list</var> to <var>s</var>.
2719 <li>Append "<code>)</code>" (U+0029) to <var>s</var>.
2720 <li>Return <var>s</var>.
2721 </ol>
2724 <dt><frequency>
2725 <dd>The frequency in hertz serialized as per <number> followed by
2726 the literal string "<code>hz</code>".
2728 <dt><identifier>
2729 <dd>The identifier
2730 <a lt="serialize an identifier">escaped</a>.
2732 <dt><integer>
2733 <dd>A base-ten integer using digits 0-9 (U+0030 to U+0039) in the
2734 shortest form possible, preceded by "<code>-</code>" (U+002D) if it is
2735 negative.
2737 <dt><length>
2738 <dd>
2739 A length of zero is represented by the literal string
2740 "<code>0px</code>".
2742 Absolute lengths: the number of millimeters serialized as per
2743 <number> followed by the literal string "<code>mm</code>".
2744 Issue: Rumor has it absolute lengths will become relative
2745 lengths. Centimeters would be compatible with <resolution>...
2747 Relative lengths: the <number> component serialized as per
2748 <number> followed by the unit in its canonical form as defined in its
2749 respective specification.
2752 <dt><number>
2753 <dd>
2754 A base-ten number using digits 0-9 (U+0030 to U+0039) in the shortest form possible,
2755 using "<code>.</code>" to separate decimals (if any),
2756 rounding the value if necessary to not produce more than 6 decimals,
2757 preceded by "<code>-</code>" (U+002D) if it is negative.
2759 Note: scientific notation is not used.
2761 <dt><percentage>
2762 <dd>The <number> component serialized as per <number> followed
2763 by the literal string "<code>%</code>" (U+0025).
2765 <dt><resolution>
2766 <dd>The resolution in dots per centimeter serialized as per
2767 <number> followed by the literal string "<code>dpcm</code>".
2769 <dt><shape>
2770 <dd>
2771 The return value of the following algorithm:
2772 <ol>
2773 <li>Let <var>s</var> be the string "<code>rect(</code>".
2774 <li>Let <var>list</var> be a list of the CSS component values belonging to <shape>.
2775 <li>Let each item in <var>list</var> be the result of invoking <a>serialize a CSS component value</a> of that item.
2776 <li>Append the result of invoking <a>serialize a comma-separated list</a> on <var>list</var> to <var>s</var>.
2777 <li>Append "<code>)</code>" (U+0029) to <var>s</var>.
2778 <li>Return <var>s</var>.
2779 </ol>
2782 <dt><string>
2783 <dt><family-name>
2784 <dt><specific-voice>
2785 <dd>The string
2786 <a lt="serialize a string">string escaped</a>.
2788 <dt><time>
2789 <dd>The time in seconds serialized as per <number> followed by
2790 the literal string "<code>s</code>".
2792 <dt><uri>
2793 <dd>The <a>absolute URL</a>
2794 <a lt="serialize a URL">URL escaped</a>.
2795 </dl>
2798 <absolute-size>,
2799 <border-width>,
2800 <border-style>,
2801 <bottom>,
2802 <generic-family>,
2803 <generic-voice>,
2804 <left>,
2805 <margin-width>,
2806 <padding-width>,
2807 <relative-size>,
2808 <right>, and
2809 <top>,
2810 are considered macros by this specification. They all represent instances
2811 of components outlined above.
2813 Issue: One idea is that we can remove this section somewhere in
2814 the CSS3/CSS4 timeline by moving the above definitions to the drafts that
2815 define the CSS components.
2818 #### Examples #### {#serializing-css-values-examples}
2820 Here are some examples of before and after results on specified values.
2821 The before column could be what the author wrote in a style sheet, while
2822 the after column shows what querying the DOM would return.
2824 <div class="example">
2825 <table class="complex data">
2826 <thead>
2827 <tr><th>Before<th>After
2828 <tbody>
2829 <tr><td><code>background: none</code><td><code>background: rgba(0, 0, 0, 0)</code>
2830 <tr><td><code>outline: none</code><td><code>outline: invert</code>
2831 <tr><td><code>border: none</code><td><code>border: medium</code>
2832 <tr><td><code>list-style: none</code><td><code>list-style: disc</code>
2833 <tr><td><code>margin: 0 1px 1px 1px</code><td><code>margin: 0px 1px 1px</code>
2834 <tr><td><code>azimuth: behind left</code><td><code>azimuth: 220deg</code>
2835 <tr><td><code>font-family: a, 'b"', serif</code><td><code>font-family: "a", "b\"", serif</code>
2836 <tr><td><code>content: url('h)i') '\[\]'</code><td><code>content: url("h)i") "[]"</code>
2837 <tr><td><code>azimuth: leftwards</code><td><code>azimuth: leftwards</code>
2838 <tr><td><code>color: rgb(18, 52, 86)</code><td><code>color: #123456</code>
2839 <tr><td><code>color: rgba(000001, 0, 0, 1)</code><td><code>color: #000000</code>
2840 </table>
2842 Issue: Some of these need to be updated per the new rules.
2843 </div>
2846 DOM Access to CSS Declaration Blocks {#dom-access-to-css-declaration-blocks}
2847 ============================================================================
2850 The {{ElementCSSInlineStyle}} Interface {#the-elementcssinlinestyle-interface}
2851 ------------------------------------------------------------------------------
2853 The <code>ElementCSSInlineStyle</code> interface provides access to inline style properties of an element.
2855 <pre class=idl>
2856 [NoInterfaceObject]
2857 interface ElementCSSInlineStyle {
2858 [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
2859 };
2860 </pre>
2862 The <dfn attribute for=ElementCSSInlineStyle>style</dfn> attribute must return a live <a>CSS declaration block</a> with the following
2863 properties:
2864 <dl>
2865 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2866 <dd>Unset.
2867 <dt><a for="CSSStyleDeclaration">declarations</a>
2868 <dd>The result of <a lt="Parse a CSS declaration block">parsing</a> the <code>style</code> content attribute, in
2869 <a>specified order</a>. If the <code>style</code> content attribute is absent, the object represents an
2870 empty list of <a>CSS declarations</a>. Mutating the <a for="CSSStyleDeclaration">declarations</a>
2871 must set the <code>style</code> content attribute on the <a>context object</a> to the
2872 <a lt="serialize a CSS declaration block">serialization</a> of the <a for="CSSStyleDeclaration">declarations</a>. If the
2873 <code>style</code> content attribute is set, changed or removed, the <a for="CSSStyleDeclaration">declarations</a> must be
2874 updated as appropriate.
2875 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
2876 <dd>Null.
2877 <dt><a for="CSSStyleDeclaration">owner node</a>
2878 <dd>The <a>context object</a>.
2879 </dl>
2881 If the user agent supports HTML, the following IDL applies: [[HTML]]
2883 <pre class=idl>
2884 HTMLElement implements ElementCSSInlineStyle;
2885 </pre>
2887 If the user agent supports SVG, the following IDL applies: [[SVG]]
2889 <pre class=idl>
2890 SVGElement implements ElementCSSInlineStyle;
2891 </pre>
2894 Extensions to the {{Window}} Interface {#extensions-to-the-window-interface}
2895 ----------------------------------------------------------------------------
2897 <pre class=idl>
2898 partial interface Window {
2899 [NewObject] CSSStyleDeclaration getComputedStyle(Element elt, optional DOMString? pseudoElt);
2900 };
2901 </pre>
2903 The <dfn method for=Window>getComputedStyle(<var>elt</var>, <var>pseudoElt</var>)</dfn> method must run these
2904 steps:
2905 <ol>
2906 <li>Let <var>doc</var> be the
2907 {{Document}}
2908 associated with the <code>Window</code> object on
2909 which the method was invoked.
2910 <li>Let <var>obj</var> be <var>elt</var>.
2911 <li>If <var>pseudoElt</var> is as an
2912 <a>ASCII case-insensitive</a> match for
2913 either ':before' or '::before' let
2914 <var>obj</var> be the ''::before'' pseudo-element of
2915 <var>elt</var>.
2916 <li>If <var>pseudoElt</var> is as an
2917 <a>ASCII case-insensitive</a> match for
2918 either ':after' or '::after' let
2919 <var>obj</var> be the ''::after'' pseudo-element of
2920 <var>elt</var>.
2921 <li>
2922 Return a live <a>CSS declaration block</a> with the following properties:
2923 <dl>
2924 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2925 <dd>Set.
2926 <dt><a for="CSSStyleDeclaration">declarations</a>
2927 <dd>All longhand properties that are <a lt="supported CSS property">supported CSS properties</a>, in lexicographical order, with the value being
2928 the <a>resolved value</a> computed for <var>obj</var> using the style rules associated with <var>doc</var>.
2929 Note: This means that even if <var>obj</var> is in a different document (e.g. one fetched via <code>XMLHttpRequest</code>) it will still use
2930 the style rules associated with the document that is associated with the global object on which
2931 {{Window/getComputedStyle()}} was invoked to compute the <a>CSS declaration block</a>.
2932 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
2933 <dd>Null.
2934 <dt><a for="CSSStyleDeclaration">owner node</a>
2935 <dd><var>obj</var>.
2936 </dl>
2938 </ol>
2939 Note: Because of historical IDL limitations the {{Window/getComputedStyle()}} method used to be on
2940 a separate interface, <code>ViewCSS</code>.
2942 <p class=warning>The {{Window/getComputedStyle()}} method exposes information from <a lt="CSS style sheet">CSS style
2943 sheets</a> with the <a>origin-clean flag</a> unset.
2945 The {{GetStyleUtils}} Interface {#the-getstyleutils-interface}
2946 --------------------------------------------------------------
2948 The <dfn>associated document</dfn> of an object <var>obj</var> is <var>obj</var>'s <a>node
2949 document</a> if <var>obj</var> is an <code>Element</code> object, or <var>obj</var>'s associated
2950 <code>Element</code> object's <a>node document</a> if <var>obj</var> is a
2951 {{PseudoElement}} object.
2953 <pre class=idl>
2954 [NoInterfaceObject]
2955 interface GetStyleUtils {
2956 [SameObject] readonly attribute CSSStyleDeclaration cascadedStyle;
2957 [SameObject] readonly attribute CSSStyleDeclaration defaultStyle;
2958 [SameObject] readonly attribute CSSStyleDeclaration rawComputedStyle;
2959 [SameObject] readonly attribute CSSStyleDeclaration usedStyle;
2960 };
2961 </pre>
2963 <p class=atrisk>The <dfn attribute for=GetStyleUtils>cascadedStyle</dfn> attribute must return a live <a>CSS declaration block</a>
2964 with the following properties:
2965 <dl>
2966 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2967 <dd>Set.
2968 <dt><a for="CSSStyleDeclaration">declarations</a>
2969 <dd>All longhand properties that are <a lt="supported CSS property">supported CSS properties</a>, in lexicographical order, that have a
2970 <a>cascaded value</a> for the <a>context object</a>, with the value being the <a>cascaded value</a> computed for the
2971 <a>context object</a> using the style rules associated with the <a>context object</a>'s <a>associated
2972 document</a>.
2973 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
2974 <dd>Null.
2975 <dt><a for="CSSStyleDeclaration">owner node</a>
2976 <dd>The <a>context object</a>.
2977 </dl>
2979 <p class=atrisk>The <dfn attribute for=GetStyleUtils>defaultStyle</dfn> attribute must return a live <a>CSS declaration block</a>
2980 with the following properties:
2981 <dl>
2982 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2983 <dd>Set.
2984 <dt><a for="CSSStyleDeclaration">declarations</a>
2985 <dd>All longhand properties that are <a lt="supported CSS property">supported CSS properties</a>, in lexicographical order, with the value being
2986 the <a>computed value</a> computed for the <a>context object</a> using the user-agent-level style rules and user-level style
2987 rules associated with the <a>context object</a>'s <a>associated document</a>, ignoring transitions, animations, author-level
2988 style rules, author-level presentational hints and override-level style rules.
2989 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
2990 <dd>Null.
2991 <dt><a for="CSSStyleDeclaration">owner node</a>
2992 <dd>The <a>context object</a>.
2993 </dl>
2995 <p class=atrisk>The <dfn attribute for=GetStyleUtils>rawComputedStyle</dfn> attribute must return a live <a>CSS declaration
2996 block</a> with the following properties:
2997 <dl>
2998 <dt><a for="CSSStyleDeclaration">readonly flag</a>
2999 <dd>Set.
3000 <dt><a for="CSSStyleDeclaration">declarations</a>
3001 <dd>All longhand properties that are <a lt="supported CSS property">supported CSS properties</a>, in lexicographical order, with the value being
3002 the <a>computed value</a> computed for the <a>context object</a> using the style rules associated with the
3003 <a>context object</a>'s <a>associated document</a>.
3004 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
3005 <dd>Null.
3006 <dt><a for="CSSStyleDeclaration">owner node</a>
3007 <dd>The <a>context object</a>.
3008 </dl>
3010 <p class=atrisk>The <dfn attribute for=GetStyleUtils>usedStyle</dfn> attribute must return a live <a>CSS declaration block</a> with the
3011 following properties:
3012 <dl>
3013 <dt><a for="CSSStyleDeclaration">readonly flag</a>
3014 <dd>Set.
3015 <dt><a for="CSSStyleDeclaration">declarations</a>
3016 <dd>All longhand properties that are <a lt="supported CSS property">supported CSS properties</a>, in lexicographical order, with the value being
3017 the <a>used value</a> computed for the <a>context object</a> using the style rules associated with the
3018 <a>context object</a>'s <a>associated document</a>.
3019 <dt><a for="CSSStyleDeclaration">parent CSS rule</a>
3020 <dd>Null.
3021 <dt><a for="CSSStyleDeclaration">owner node</a>
3022 <dd>The <a>context object</a>.
3023 </dl>
3025 <p class=warning>The {{GetStyleUtils/cascadedStyle}}, {{GetStyleUtils/rawComputedStyle}}
3026 and {{GetStyleUtils/usedStyle}} methods expose information from <a>CSS style sheets</a> with the
3027 <a>origin-clean flag</a> unset.
3030 Extensions to the {{Element}} Interface {#extensions-to-the-element-interface}
3031 ------------------------------------------------------------------------------
3033 <pre class=idl>
3034 partial interface Element {
3035 PseudoElement? pseudo(DOMString pseudoElt);
3036 };
3038 Element implements GetStyleUtils;
3039 </pre>
3041 <p class=atrisk>The <dfn method for=Element>pseudo(<var>pseudoElt</var>)</dfn> method, when invoked, must run the following steps:
3042 <ol>
3043 <li>If <var>pseudoElt</var> is as an <a>ASCII case-insensitive</a> match for either ':before' or
3044 '::before' return the {{PseudoElement}} representing the ''::before'' pseudo-element of the
3045 <a>context object</a>.
3046 <li>If <var>pseudoElt</var> is as an <a>ASCII case-insensitive</a> match for either ':after' or
3047 '::after' return the {{PseudoElement}} representing the ''::after'' pseudo-element of the
3048 <a>context object</a>.
3049 <li>Return null.
3050 </ol>
3051 When invoked with an argument that returns a {{PseudoElement}} object representing a particular pseudo-element, the same object must be
3052 returned as returned by an earlier call that represent the same pseudo-element.
3056 The {{PseudoElement}} Interface {#the-pseudoelement-interface}
3057 --------------------------------------------------------------
3059 <p class=atrisk>The {{PseudoElement}} interface is used for representing CSS pseudo-elements. A {{PseudoElement}} object is associated with an
3060 <code>Element</code> object.
3062 Issue: This should be merged with the {{CSSPseudoElement}} proposal.
3064 <pre class=idl>
3065 interface PseudoElement {
3066 <!-- XXX
3067 // type
3068 // style
3069 // ownerElement
3070 // querySelector should return PseudoElements
3071 // Extend Event to expose PseudoElement?
3072 -->
3073 };
3075 PseudoElement implements GetStyleUtils;
3076 </pre>
3079 Utility APIs {#utility-apis}
3080 ============================
3082 The <code>CSS.escape()</code> Method {#the-css.escape()-method}
3083 ------------------------------------------------------
3085 The <code>CSS</code> interface holds useful CSS-related functions that do not belong elsewhere.
3087 <pre class=idl>
3088 interface CSS {
3089 static DOMString escape(DOMString ident);
3090 };
3091 </pre>
3093 The <dfn method for=CSS>escape(<var>ident</var>)</dfn> method must return the result of invoking <a>serialize an identifier</a> of
3094 <var>ident</var>.
3096 <div class=example>
3097 For example, to escape a string for use as part of a selector, the {{CSS/escape()}} method can be used:
3098 <pre>var element = document.querySelector('#' + CSS.escape(id) + ' > img');</pre>
3099 </div>
3101 <div class=example>
3102 The {{CSS/escape()}} method can also be used for escaping strings, although it escapes characters that don't strictly need to be
3103 escaped:
3104 <pre>var element = document.querySelector('a[href="#' + CSS.escape(fragment) + '"]');</pre>
3105 </div>
3108 Resolved Values {#resolved-values}
3109 ==================================
3111 <code lt="dom-Window-getComputedStyle()">getComputedStyle()</code> was
3112 historically defined to return the "computed value" of an element or
3113 pseudo-element. However, the concept of "computed value" changed between
3114 revisions of CSS while the implementation of
3115 <code lt="dom-Window-getComputedStyle()">getComputedStyle()</code> had to
3116 remain the same for compatibility with deployed scripts. To address this
3117 issue this specification introduces the concept of a
3118 <dfn>resolved value</dfn>.
3120 The <a>resolved value</a> for a given property can be determined
3121 as follows:
3123 <dl class="switch">
3124 <!--
3125 We want to treat shorthand properties like any other value basically.
3127 <dt>'background'
3128 <dt>'border'
3129 <dt>'border-collapse'
3130 <dt>'border-color'
3131 <dt>'border-spacing'
3132 <dt>'border-style'
3133 <dt>'border-top'
3134 <dt>'border-right'
3135 <dt>'border-bottom'
3136 <dt>'border-left'
3137 <dt>'border-width'
3138 <dt>'font'
3139 <dt>'list-style'
3140 <dt>'margin'
3141 <dt>'outline'
3142 <!- - overflow is not - ->
3143 <dt>'padding'
3144 <dt>'pause'
3145 <dd>
3146 There is no <a>resolved value</a>.
3148 -->
3150 <dt>'line-height'
3151 <dd>The <a>resolved value</a> is the <a>used value</a>.
3153 <dt>'height'
3154 <dt>'margin'
3155 <dt>'margin-bottom'
3156 <dt>'margin-left'
3157 <dt>'margin-right'
3158 <dt>'margin-top'
3159 <dt>'padding'
3160 <dt>'padding-bottom'
3161 <dt>'padding-left'
3162 <dt>'padding-right'
3163 <dt>'padding-top'
3164 <dt>'width'
3165 <dd>If the property applies to the element or pseudo-element and the
3166 <a>resolved value</a> of the 'display' property is not
3167 ''display/none'', the <a>resolved value</a> is the
3168 <a>used value</a>. Otherwise the <a>resolved value</a> is the
3169 <a>computed value</a>.
3171 <dt>'bottom'
3172 <dt>'left'
3173 <dt>'right'
3174 <dt>'top'
3175 <dd>If the property applies to a positioned element and the
3176 <a>resolved value</a> of the 'display' property is not
3177 ''display/none'', the <a>resolved value</a> is the
3178 <a>used value</a>. Otherwise the <a>resolved value</a> is the
3179 computed value.
3181 <dt>Any other property
3182 <dd>The <a>resolved value</a> is the <a>computed value</a>.
3183 </dl>
3186 IANA Considerations {#iana-considerations}
3187 ==========================================
3190 Default-Style {#default-style}
3191 ------------------------------------------------------------------------------------
3193 This section describes a header field for registration in the Permanent
3194 Message Header Field Registry.
3195 <!--<a href="issue">\[RFC3864]</a>-->
3197 <dl>
3198 <dt>Header field name
3199 <dd><dfn lt="http-default-style">Default-Style</dfn>
3200 <dt>Applicable protocol
3201 <dd>http
3202 <dt>Status
3203 <dd>standard
3204 <dt>Author/Change controller
3205 <dd>W3C
3206 <dt>Specification document(s)
3207 <dd>This document is the relevant specification.
3208 <dt>Related information
3209 <dd>None.
3210 </dl>
3214 Change History {#change-history}
3215 ================================
3217 This section documents some of the changes between publications of this specification. This section is not exhaustive. Bug fixes and editorial changes are
3218 generally not listed.
3220 <!--
3222 CSSCharsetRule is re-dropped.
3224 -->
3226 Changes From 12 July 2011 To 5 December 2013 {#changes-from-12-july-2011-to-5-december-2013}
3227 --------------------------------------------------------------------------------------------
3229 <ul>
3230 <li>Cross-origin stylesheets are not allowed to be read or changed.
3232 <li><code>CSSCharsetRule</code> is re-introduced.
3234 <li><code>CSSGroupingRule</code> and <code>CSSMarginRule</code> are introduced.
3236 <li><code>CSSNamespaceRule</code> is now mutable.
3238 <li><a lt="parse a CSS declaration block">Parse</a> and <a lt="serialize a CSS declaration block">serialize</a> a CSS declaration block is
3239 now defined.
3241 <li>Shorthands are now supported in {{CSSStyleDeclaration/setProperty()}},
3242 {{CSSStyleDeclaration/getPropertyValue()}}, et al.
3244 <li>{{CSSStyleDeclaration/setPropertyValue()}} and
3245 {{CSSStyleDeclaration/setPropertyPriority()}} are introduced.
3247 <li>The <code>style</code> and <code>media</code> attributes of various interfaces are annotated with the <code>[PutForwards]</code> WebIDL
3248 extended attribute.
3250 <li>The {{Element/pseudo()}} method on <code>Element</code> is introduced.
3252 <li>The {{PseudoElement}} interface is introduced.
3254 <li>The {{GetStyleUtils/cascadedStyle}}, .{{GetStyleUtils/rawComputedStyle}} and
3255 {{GetStyleUtils/usedStyle}} attributes on <code>Element</code> and {{PseudoElement}} are introduced.
3257 <li>The <code method for=CSS>CSS.escape()</code> static method is introduced.
3258 </ul>
3260 <!--
3261 This section documents the primary technical changes of CSSOM related functionality, with a focus on changes to API signatures.
3263 <h3 class="no-num">Changes From DOM-2 Style</h3>
3265 <ul>
3266 <li>Remove definition of <code>CSSRule.UNKNOWN_RULE</code>, reserving its value (0) to prevent future reuse.
3267 <li>Remove definition of <code>DOMImplementationCSS</code> interface.
3268 </ul>
3269 -->
3271 Acknowledgments {#acknowledgments}
3272 ==================================
3274 The editors would like to thank
3275 Alexey Feldgendler,
3276 Benjamin Poulain,
3277 Björn Höhrmann,
3278 Boris Zbasky,
3279 Brian Kardell,
3280 Christian Krebs,
3281 Daniel Glazman,
3282 David Baron,
3283 <i>fantasai</i>,
3284 Hallvord R. M. Steen,
3285 Ian Hickson,
3286 John Daggett,
3287 Lachlan Hunt,
3288 Mike Sherov,
3289 Morten Stenshorne,
3290 Ms2ger,
3291 Ãyvind Stenhaug,
3292 Peter Sloetjes,
3293 Philip Jägenstedt,
3294 Philip Taylor,
3295 Richard Gibson,
3296 Robert O'Callahan,
3297 Simon Sapin,
3298 Sjoerd Visscher,
3299 Sylvain Galineau,
3300 Tarquin Wilton-Jones, and
3301 Zack Weinberg
3302 for contributing to this specification.
3304 Additional thanks to Ian Hickson for writing the
3305 initial version of the alternative style sheets API and canonicalization
3306 (now serialization) rules for CSS values.
3308 <!-- XXX NOTES
3310 <style type=text/css;charset=utf-8> does create a StyleSheet in Firefox
3311 and Opera, but does not create a StyleSheet in IE. I prefer IE.
3313 <style type=TEXT/CSS> sets the style sheet type to text/css in Firefox and
3314 TEXT/CSS in Opera and IE. I prefer Firefox.
3316 <style> sets the style sheet location to the document location Firefox,
3317 the empty string in IE, and null in Opera. I prefer Opera
3319 <style media="x"> invokes .sheet.media.mediaText = "x"
3321 <style> does not "have" a title
3323 .cascadedStyle that returns less keywords than currentStyle, no inherit,
3324 etc.
3326 Markup style: http://krijnhoetmer.nl/irc-logs/whatwg/20100204#l-529
3327 -->
3328 </body>
3329 </html>