CINXE.COM
CSS Scoping Module Level 1
<!DOCTYPE html><html lang=en><head> <meta content="text/html; charset=utf-8" http-equiv=Content-Type> <title>CSS Scoping Module Level 1</title> <link href=default.css rel=stylesheet type=text/css> <link href="https://www.w3.org/StyleSheets/TR/W3C-WD" rel=stylesheet type=text/css> </head> <body class=h-entry> <div class=head> <p><a href="https://www.w3.org/"> <img alt=W3C height=48 src="https://www.w3.org/Icons/w3c_home" width=72> </a> </p> <h1 class="p-name no-ref" id=title>CSS Scoping Module Level 1</h1> <h2 class="no-num no-toc no-ref heading settled heading" id=subtitle><span class=content>W3C First Public Working Draft, <span class=dt-updated><span class=value-title title=20140403>3 April 2014</span></span></span></h2> <div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href="https://www.w3.org/TR/2014/WD-css-scoping-1-20140403/">http://www.w3.org/TR/2014/WD-css-scoping-1-20140403/</a><dt>Latest version:<dd><a href="https://www.w3.org/TR/css-scoping-1/">http://www.w3.org/TR/css-scoping-1/</a><dt>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/css-scoping/>http://dev.w3.org/csswg/css-scoping/</a> <dt>Feedback:</dt> <dd><a href="mailto:www-style@w3.org?subject=%5Bcss-scoping%5D%20feedback">www-style@w3.org</a> with subject line “<kbd>[css-scoping] <var>… message topic …</var></kbd>”(<a href=http://lists.w3.org/Archives/Public/www-style/ rel=discussion>archives</a>)<dt>Test Suite:<dd>None Yet<dt>Editors: <dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://xanthir.com/contact/>Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)<dd class="p-author h-card vcard"><a class="p-name fn u-url url" href=http://fantasai.inkedblade.net/contact>Elika J Etemad</a> (<span class="p-org org">Invited Expert</span>)</dl></div> <div data-fill-with=warning></div> <p class=copyright data-fill-with=copyright><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2014 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href=http://www.csail.mit.edu/><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href=http://www.ercim.eu/><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href=http://www.keio.ac.jp/>Keio</a>, <a href=http://ev.buaa.edu.cn/>Beihang</a>), All Rights Reserved. W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply. </p> <hr title="Separator for header"> </div> <h2 class="no-num no-toc no-ref heading settled heading" id=abstract><span class=content>Abstract</span></h2> <p class=p-summary data-fill-with=abstract>This specification defines various scoping/encapsulation mechanisms for CSS, including scoped styles and the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rule, Shadow DOM selectors, and page/region-based styling. <a href="https://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.</p> <h2 class="no-num no-toc no-ref heading settled heading" id=status><span class=content>Status of this document</span></h2> <div data-fill-with=status><p><em>This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the <a href="https://www.w3.org/TR/">W3C technical reports index at http://www.w3.org/TR/.</a></em> <p>This document is a <b>First Public Working Draft</b>. <p>Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress. <p>The (<a href=http://lists.w3.org/Archives/Public/www-style/>archived</a>) public mailing list <a href=mailto:www-style@w3.org>www-style@w3.org</a> (see <a href="https://www.w3.org/Mail/Request">instructions</a>) is preferred for discussion of this specification. When sending e-mail, please put the text “css-scoping” in the subject, preferably like this: “[css-scoping] <em>…summary of comment…</em>” <p>This document was produced by the <a href="https://www.w3.org/Style/CSS/members">CSS Working Group</a> (part of the <a href="https://www.w3.org/Style/">Style Activity</a>). <p>This document was produced by a group operating under the <a href="https://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>. W3C maintains a <a href="https://www.w3.org/2004/01/pp-impl/32061/status" rel=disclosure>public list of any patent disclosures</a> made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains <a href="https://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.</p> </div> <div data-fill-with=at-risk></div> <h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of Contents</span></h2> <div data-fill-with=table-of-contents><ul class=toc> <li><a href=#intro><span class=secno>1</span> Introduction</a> <li><a href=#scope><span class=secno>2</span> Scoped Styles</a> <ul class=toc> <li><a href=#scoping-mechanisms><span class=secno>2.1</span> Scoping Mechanisms</a> <ul class=toc> <li><a href=#scoping-markup><span class=secno>2.1.1</span> Document Markup for Scoping</a> <li><a href=#scope-atrule><span class=secno>2.1.2</span> CSS Syntax for Scoping: the <span class=css data-link-type=maybe title=@scope>@scope</span> rule</a></ul> <li><a href=#scoping-context><span class=secno>2.2</span> Querying the Scoping Context</a> <ul class=toc> <li><a href=#scope-pseudo><span class=secno>2.2.1</span> Selecting the Scoping Root: <span class=css data-link-type=maybe title=:scope>:scope</span> pseudo-class</a> <li><a href=#scope-content-pseudo><span class=secno>2.2.2</span> Selecting Outside the Scope: <span class=css data-link-type=maybe title=:scope-context()>:scope-context()</span> pseudo-class</a></ul></ul> <li><a href=#shadow-dom><span class=secno>3</span> Shadow Encapsulation</a> <ul class=toc> <li><a href=#selectors-data-model><span class=secno>3.1</span> Shadow DOM Selection Model</a> <ul class=toc> <li><a href=#host-element><span class=secno>3.1.1</span> Host Elements in a Shadow Tree</a></ul> <li><a href=#selectors><span class=secno>3.2</span> Shadow DOM Selectors</a> <ul class=toc> <li><a href=#host-selector><span class=secno>3.2.1</span> Selecting Into the Light: the <span class=css data-link-type=maybe title=:host>:host</span>, <span class=css data-link-type=maybe title=:host()>:host()</span>, and <span class=css data-link-type=maybe title=:host-context()>:host-context()</span> pseudo-classes</a> <li><a href=#shadow-pseudoelement><span class=secno>3.2.2</span> Selecting Into the Dark: the <span class=css data-link-type=maybe title=::shadow>::shadow</span> pseudo-element</a> <li><a href=#content-combinator><span class=secno>3.2.3</span> Selecting Shadow-Projected Content: the <span class=css data-link-type=maybe title=::content>::content</span> pseudo-element</a> <li><a href=#deep-combinator><span class=secno>3.2.4</span> Selecting Through Shadows: the <span class=css data-link-type=maybe title=/deep/>/deep/</span> combinator</a></ul> <li><a href=#shadow-cascading><span class=secno>3.3</span> Shadow Cascading & Inheritance</a> <ul class=toc> <li><a href=#cascading><span class=secno>3.3.1</span> Cascading</a> <li><a href=#inheritance><span class=secno>3.3.2</span> Inheritance</a></ul></ul> <li><a href=#fragment-scoping><span class=secno>4</span> Fragmented Styling</a> <ul class=toc> <li><a href=#the-region-pseudo-element><span class=secno>4.1</span> Region-based Styling: the <span class=css data-link-type=maybe title=::region>::region</span> pseudo-element</a></ul> <li><a href=#conformance><span class=secno></span> Conformance</a> <ul class=toc> <li><a href=#conventions><span class=secno></span> Document conventions</a> <li><a href=#conformance-classes><span class=secno></span> Conformance classes</a> <li><a href=#partial><span class=secno></span> Partial implementations</a> <li><a href=#experimental><span class=secno></span> Experimental implementations</a> <li><a href=#testing><span class=secno></span> Non-experimental implementations</a></ul> <li><a href=#references><span class=secno></span> References</a> <ul class=toc> <li><a href=#normative><span class=secno></span> Normative References</a> <li><a href=#informative><span class=secno></span> Informative References</a></ul> <li><a href=#index><span class=secno></span> Index</a> <li><a href=#property-index><span class=secno></span> Property index</a> <li><a href=#issues-index><span class=secno></span>Issues Index</a></ul></div> <h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content> Introduction</span><a class=self-link href=#intro></a></h2> <p> ... <h2 class="heading settled heading" data-level=2 id=scope><span class=secno>2 </span><span class=content> Scoped Styles</span><a class=self-link href=#scope></a></h2> <p> <a data-link-type=dfn href="https://www.w3.org/TR/css3-cascade/#scoped" title=scoped>Scoped</a> style rules apply only within a subtree of a document, rather than matching against the entire document. Scoping has two primary effects: <ul> <li>The selector of the <a data-link-type=dfn href="https://www.w3.org/TR/css3-cascade/#scoped" title=scoped>scoped</a> style rule is restricted to match only elements within scope. See <a href="https://www.w3.org/TR/selectors4/#scoping">Scoped Selectors</a> in <a data-biblio-type=informative data-link-type=biblio href=#selectors4 title=selectors4>[SELECTORS4]</a>. <li>The cascade prioritizes scoped rules over unscoped ones, regardless of specificity. See <a href="https://www.w3.org/TR/css-cascade/#cascade-scope">Cascading by Scope</a> in <a data-biblio-type=informative data-link-type=biblio href=#css3cascade title=css3cascade>[CSS3CASCADE]</a>. </ul> <h3 class="heading settled heading" data-level=2.1 id=scoping-mechanisms><span class=secno>2.1 </span><span class=content> Scoping Mechanisms</span><a class=self-link href=#scoping-mechanisms></a></h3> <p> Style rules can be scoped using constructs defined in the document language or using the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rule in CSS. <h4 class="heading settled heading" data-level=2.1.1 id=scoping-markup><span class=secno>2.1.1 </span><span class=content> Document Markup for Scoping</span><a class=self-link href=#scoping-markup></a></h4> <p> Document languages may define a mechanism for a stylesheet to be scoped to some element in the document. For example, in HTML, a <a data-link-type=element href="https://www.w3.org/TR/html5/document-metadata.html#the-style-element" title=style>style</a> element with a <a data-link-for=style data-link-type=element-attr title=scoped>scoped</a> attribute defines a stylesheet that is scoped to the <a data-link-type=element href="https://www.w3.org/TR/html5/document-metadata.html#the-style-element" title=style>style</a> element’s parent element. <a data-biblio-type=informative data-link-type=biblio href=#html title=html>[HTML]</a> <h4 class="heading settled heading" data-level=2.1.2 id=scope-atrule><span class=secno>2.1.2 </span><span class=content> CSS Syntax for Scoping: the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rule</span><a class=self-link href=#scope-atrule></a></h4> <p> The <dfn class=css-code data-dfn-type=at-rule data-export="" id=at-ruledef-scope>@scope<a class=self-link href=#at-ruledef-scope></a></dfn> at-rule allows authors to create scoped style rules using CSS syntax. The syntax of the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rule is: <pre class=prod>@scope <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a> { <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/css3-syntax/#typedef-stylesheet" title="<stylesheet>"><stylesheet></a> } </pre> <p> where the elements matched by the <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a> are <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping roots">scoping roots</a> for the style rules in <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/css3-syntax/#typedef-stylesheet" title="<stylesheet>"><stylesheet></a>, and selectors of style rules scoped by <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> are <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scope-contained- title=scope-contained>scope-contained</a> to their <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a>. <p class=issue id=issue-5f568f10><a class=self-link href=#issue-5f568f10></a> This rule makes it very easy for authors to create scoped style sheets, which could affect the optimization strategies for implementing scoped styles. <p> If multiple elements match the <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>, the <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/css3-syntax/#typedef-stylesheet" title="<stylesheet>"><stylesheet></a> is effectively duplicated and scoped independently to each one. Authors should avoid using overly-generic selectors as it can have confusing interactions with the cascade. <div class=example> A scoped stylesheet is attached not only to the outermost scoping element, but to all matching elements. For example, given the style sheet below <pre>@scope div { span { color: blue; } } @scope section { span { color: orange; } } </pre> <p> and the following document fragment <pre><div> <section> <div> <span>text</span> </div> </section> </div> </pre> <p> the text will be blue. </div> <p> <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rules can be nested. In this case, just as with the nested style rules, the selector of an outer <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> scope-contains the selector of the inner one. <p> The specificity of selectors inside the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rule is calculated locally: the selector specifying the scoping element is ignored. However, because scoped styles override non-scoped styles, style rules inside the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> will override rules outside of it. <div class=example> In the following example, the text would be green: <pre> @scope aside { p { color: green; } } aside#sidebar p { color: red; } </pre> </div> <p class=issue id=issue-5c7571b6><a class=self-link href=#issue-5c7571b6></a> If multiple <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rules apply to an element, should they be cascaded by specificity? <h3 class="heading settled heading" data-level=2.2 id=scoping-context><span class=secno>2.2 </span><span class=content> Querying the Scoping Context</span><a class=self-link href=#scoping-context></a></h3> <h4 class="heading settled heading" data-level=2.2.1 id=scope-pseudo><span class=secno>2.2.1 </span><span class=content> Selecting the Scoping Root: <a class=css data-link-type=maybe href="https://www.w3.org/TR/selectors4/#scope-pseudo" title=:scope>:scope</a> pseudo-class</span><a class=self-link href=#scope-pseudo></a></h4> <p> In a scoped stylesheet, the <a class=css data-link-type=maybe href="https://www.w3.org/TR/selectors4/#scope-pseudo" title=:scope>:scope</a> pseudo-class, defined in <a data-biblio-type=informative data-link-type=biblio href=#selectors4 title=selectors4>[SELECTORS4]</a>, matches the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a>. <h4 class="heading settled heading" data-level=2.2.2 id=scope-content-pseudo><span class=secno>2.2.2 </span><span class=content> Selecting Outside the Scope: <span class=css data-link-type=maybe title=:scope-context()>:scope-context()</span> pseudo-class</span><a class=self-link href=#scope-content-pseudo></a></h4> <div class=issue id=issue-aecbd194><a class=self-link href=#issue-aecbd194></a> This would be defined similarly to <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a>, but matching the ancestors of the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a> instead. <p> However, since for scoped stylesheets you may want the ability to match complex selectors against the outside tree, rather than a single compound selector, we may want to instead use a more general mechanism that doesn’t syntactically invert the order of tree elements. <p> Possible ideas: <pre>:scope-context(<a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>) div {...} scope(<a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>) div {...} \scope <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>\ div {...} <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a> \scope\ div {...} </pre> <p> This functionality would replace <span class=css data-link-type=maybe title=@global>@global</span>, which is a poor excuse for a selector. </div> <h2 class="heading settled heading" data-level=3 id=shadow-dom><span class=secno>3 </span><span class=content> Shadow Encapsulation</span><a class=self-link href=#shadow-dom></a></h2> <p> The Shadow DOM spec augments the DOM with several new concepts, several of which are relevant to CSS. <p> A <dfn data-dfn-type=dfn data-export="" id=shadow-tree>shadow tree<a class=self-link href=#shadow-tree></a></dfn> is a document fragment that can be attached to any element in the DOM. The root of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> is a <dfn data-dfn-type=dfn data-export="" id=shadow-root>shadow root<a class=self-link href=#shadow-root></a></dfn>, a non-element node which is associated with a <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a>. An element can have any number of <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>, which are ordered by creation time. The most recently-created <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> on an element is the <dfn data-dfn-type=dfn data-export="" id=active-shadow-tree>active shadow tree<a class=self-link href=#active-shadow-tree></a></dfn> for that element. <p> An element with a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> is a <dfn data-dfn-type=dfn data-export="" id=shadow-host>shadow host<a class=self-link href=#shadow-host></a></dfn>. It is the <dfn data-dfn-type=dfn data-export="" id=host-element0>host element<a class=self-link href=#host-element0></a></dfn> for its shadow trees. <p> The descendants of a <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a> must not generate boxes in the formatting tree. Instead, the contents of the <a data-link-type=dfn href=#active-shadow-tree title="active shadow tree">active shadow tree</a> generate boxes as if they were the contents of the element instead. <p> In several instances in shadow DOM, elements don’t have element parents (instead, they may have a <a data-link-type=dfn href=#shadow-root title="shadow root">shadow root</a> as parent, or something else). An element without a parent, or whose parent is not an element, is called a <dfn data-dfn-type=dfn data-export="" id=top-level-element>top-level element<a class=self-link href=#top-level-element></a></dfn>. <p> While the children of a <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a> do not generate boxes normally, they can be explicitly pulled into a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> and forced to render normally. This is done by assigning the elements to a <dfn data-dfn-type=dfn data-export="" id=distribution-list>distribution list<a class=self-link href=#distribution-list></a></dfn>. An element with a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> is an <dfn data-dfn-type=dfn data-export="" id=insertion-point>insertion point<a class=self-link href=#insertion-point></a></dfn>. <p> This specification does not define how to assign elements to a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>, instead leaving that to the Shadow DOM spec. At the time this spec is written, however, only <a data-link-type=element title=content>content</a> elements in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> can have <a data-link-type=dfn href=#distribution-list title="distribution lists">distribution lists</a>. <p> An <a data-link-type=dfn href=#insertion-point title="insertion point">insertion point</a> must not generate any boxes. Instead, the elements in its <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> generate boxes as normal, as if they all replaced the <a data-link-type=dfn href=#insertion-point title="insertion point">insertion point</a> in-place. <span class=note>(Akin to the behavior of <a class=css data-link-type=propdesc href=http://dev.w3.org/csswg/css-display-3/#propdef-display-box title=display-box>display-box: contents</a>.)</span> <h3 class="heading settled heading" data-level=3.1 id=selectors-data-model><span class=secno>3.1 </span><span class=content> Shadow DOM Selection Model</span><a class=self-link href=#selectors-data-model></a></h3> <p> Elements in the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#element-tree title="element tree">element tree</a> additionally have zero or more <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> and zero or one <a data-link-type=dfn href=#distribution-list title="distribution lists">distribution lists</a>. <p class=note> Note: The "descendants" of an element are based on the children of the element, which does not include the <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> or <a data-link-type=dfn href=#distribution-list title="distribution lists">distribution lists</a> of the element. <p> When a selector is matched against a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#initial-selector-match-list title="initial selector match list">initial selector match list</a> is the <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a>, followed by all the <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> and their descendants, ordered by a pre-order traversal. <h4 class="heading settled heading" data-level=3.1.1 id=host-element><span class=secno>3.1.1 </span><span class=content> Host Elements in a Shadow Tree</span><a class=self-link href=#host-element></a></h4> <p> A <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a> is outside of the <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> it hosts, but it is sometimes useful to be able to style it from inside the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> context. <p> For the purpose of Selectors, a <a data-link-type=dfn href=#host-element0 title="host element">host element</a> also appears in each of its <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>, with the contents of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> treated as its children. If an element has multiple <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>, it appears in each <a data-link-type=dfn href=#shadow-tree title="shadow tree’s">shadow tree’s</a> context independently; each <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> sees <em>itself</em> as the contents of the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>, not the other <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>. <p> The <a data-link-type=dfn href=#host-element0 title="host element">host element</a> is not selectable by <strong>any means</strong> except for the <a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a> and <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-classes. That is, in this context the <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a> has no tagname, ID, classes, or attributes, and the only additional information is has is that the <a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a> pseudo-class matches it. In particular, the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> isn’t matched by the <span class=css data-link-type=maybe title=*>*</span> selector either. </p><details class=why> <summary>Why is the shadow host so weird?</summary> <p> The <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a> lives outside the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, and its markup is in control of the page author, not the component author. <p> It would not be very good if a component used a particular class name internally in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, and the page author using the component accidentally <em>also</em> used the the same class name and put it on the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>. Such a situation would result in accidental styling that is impossible for the component author to predict, and confusing for the page author to debug. <p> However, there are still some reasonable use-cases for letting a stylesheet in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> style its <a data-link-type=dfn href=#host-element0 title="host element">host element</a>. So, to allow this situation but prevent accidental styling, the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> appears but is completely featureless and unselectable except through <a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a>. </details> <h3 class="heading settled heading" data-level=3.2 id=selectors><span class=secno>3.2 </span><span class=content> Shadow DOM Selectors</span><a class=self-link href=#selectors></a></h3> <p> Shadow DOM defines a few new selectors to help select elements in useful way related to Shadow DOM. <p class=issue id=issue-dea392ae><a class=self-link href=#issue-dea392ae></a> This section is still under discussion. Feedback and advice on intuitive syntax for the following functionality would be appreciated. <h4 class="heading settled heading" data-level=3.2.1 id=host-selector><span class=secno>3.2.1 </span><span class=content> Selecting Into the Light: the <a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a>, <a class=css data-link-type=maybe href=#selectordef-host title=:host()>:host()</a>, and <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-classes</span><a class=self-link href=#host-selector></a></h4> <p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-host0>:host<a class=self-link href=#selectordef-host0></a></dfn> pseudo-class, when evaluated in the context of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, matches the <a data-link-type=dfn href=#shadow-tree title="shadow tree’s">shadow tree’s</a> <a data-link-type=dfn href=#host-element0 title="host element">host element</a>. In any other context, it matches nothing. <p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-host>:host()<a class=self-link href=#selectordef-host></a></dfn> function pseudo-class has the syntax: <pre>:host( <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltcompound-selector" title="<compound-selector>"><compound-selector></a> )</pre> <p> When evaluated in the context of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, it matches the <a data-link-type=dfn href=#shadow-tree title="shadow tree’s">shadow tree’s</a> <a data-link-type=dfn href=#host-element0 title="host element">host element</a> if the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>, in its normal context, matches the selector argument. In any other context, it matches nothing. <div class=example> For example, say you had a component with a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> like the following: <pre> <x-foo class="foo"> <"shadow tree"> <div class="foo">...</div> </> </x-foo> </pre> <p> For a stylesheet within the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>: <p> <ul> <li><a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a> matches the <code><x-foo></code> element. <li><span class=css data-link-type=maybe title=x-foo>x-foo</span> matches nothing. <li><span class=css data-link-type=maybe title=.foo>.foo</span> matches only the <code><div></code> element. <li><span class=css data-link-type=maybe title=.foo:host>.foo:host</span> matches nothing <li><span class=css data-link-type=maybe title=:host(.foo)>:host(.foo)</span> matches the <code><x-foo></code> element. </ul> </div> <p> Ordinary, selectors within a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> can’t see elements outside the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> at all. Sometimes, however, it’s useful to select an ancestor that lies somewhere outside the shadow tree, above it in the document. <div class=example> For example, a group of components can define a handful of color themes they they know how to respond to. Page authors could opt into a particular theme by adding a specific class to the components, or higher up in the document. </div> <p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-host-context>:host-context()<a class=self-link href=#selectordef-host-context></a></dfn> functional pseudo-class tests whether there is an ancestor, outside the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, which matches a particular selector. Its syntax is: <pre>:host-context( <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltcompound-selector" title="<compound-selector>"><compound-selector></a> )</pre> <p> When evaluated in the context of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, the <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-class matches the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>, if the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> or one of its ancestors matches the provided <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltcompound-selector" title="<compound-selector>"><compound-selector></a>. For the purpose of this pseudo-class, the "ancestor" of an element is: <dl> <dt>if the element is distributed to a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> <dd> the <a data-link-type=element title=content>content</a> element it is ultimately distributed to. <dt>if the element is a top-most element in a shadow tree <dd> the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> <dt>otherwise <dd> the element’s parent, if it has one. </dl> <p class=note> Note: This means that the selector pierces through shadow boundaries on the way up, looking for elements that match its argument, until it reaches the document root. <h4 class="heading settled heading" data-level=3.2.2 id=shadow-pseudoelement><span class=secno>3.2.2 </span><span class=content> Selecting Into the Dark: the <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element</span><a class=self-link href=#shadow-pseudoelement></a></h4> <p> If an element has at least one <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, the <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-shadow>::shadow<a class=self-link href=#selectordef-shadow></a></dfn> pseudo-element matches the <a data-link-type=dfn href=#shadow-root title="shadow roots">shadow roots</a> themselves. In HTML, the <a data-link-type=dfn href=#shadow-root title="shadow root">shadow root</a> is represented by <a class=idl-code data-link-type=interface title=shadowroot>ShadowRoot</a> objects. <p> The <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element must not generate boxes, unless specified otherwise in another specification. However, for the purpose of Selectors, the <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element is considered to be the root of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, with the <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> in the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> the direct children of the <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element. <div class=example> For example, say you had a component with a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> like the following: <pre> <x-foo> <"shadow tree"> <div> <span id="not-top">...</span> </div> <span id="top">...</span> </> </x-foo> </pre> <p> For a stylesheet in the outer document, <span class=css data-link-type=maybe title="x-foo::shadow > span">x-foo::shadow > span</span> matches <span class=css data-link-type=maybe title=#top>#top</span>, but not <span class=css data-link-type=maybe title=#not-top>#not-top</span>, because it’s not a <a data-link-type=dfn href=#top-level-element title="top-level element">top-level element</a> in the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>. <p> If one wanted to target <span class=css data-link-type=maybe title=#not-top>#not-top</span>, one way to do it would be with <span class=css data-link-type=maybe title="x-foo::shadow > div > span">x-foo::shadow > div > span</span>. However, this introduces a strong dependency on the internal structure of the component; in most cases, it’s better to use the descendant combinator, like <span class=css data-link-type=maybe title="x-foo::shadow span">x-foo::shadow span</span>, to select all the elements of some type in the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>. </div> <div class=example> If an element has multiple <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>, a <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element selects <em>all</em> of the corresponding <a data-link-type=dfn href=#shadow-root title="shadow roots">shadow roots</a>. <p> Similarly, inside of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, a selector like <span class=css data-link-type=maybe title=":host::shadow div">:host::shadow div</span> selects the <a data-link-type=element href="https://www.w3.org/TR/html5/grouping-content.html#the-div-element" title=div>div</a> elements in <em>all</em> the <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> on the element, not just the one containing that selector. </div> <h4 class="heading settled heading" data-level=3.2.3 id=content-combinator><span class=secno>3.2.3 </span><span class=content> Selecting Shadow-Projected Content: the <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element</span><a class=self-link href=#content-combinator></a></h4> <p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-content>::content<a class=self-link href=#selectordef-content></a></dfn> pseudo-element matches the <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> itself, on elements that have one. <p class=issue id=issue-1b6118ae><a class=self-link href=#issue-1b6118ae></a> <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> is a confusingly general name for something that is specific to the projected content of a shadow tree. <p> The <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element must not generate boxes, unless specified otherwise in another specification. However, for the purpose of Selectors, the <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element is considered to be the parent of the elements in the <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>. <div class=example> For example, say you had a component with both children and a shadow tree, like the following: <pre> <x-foo> <div id="one" class="foo">...</div> <div id="two">...</div> <div id="three" class="foo"> <div id="four">...</div> </div> <"shadow tree"> <div id="five">...</div> <div id="six">...</div> <content select=".foo"></content> </"shadow tree"> </x-foo> </pre> <p> For a stylesheet within the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, a selector like <span class=css data-link-type=maybe title="::content div">::content div</span> selects <span class=css data-link-type=maybe title=#one>#one</span>, <span class=css data-link-type=maybe title=#three>#three</span>, and <span class=css data-link-type=maybe title=#four>#four</span>, as they’re the elements distributed by the sole <a data-link-type=element title=content>content</a> element, but not <span class=css data-link-type=maybe title=#two>#two</span>. <p> If only the <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> distributed the <a data-link-type=element title=content>content</a> element are desired, a <a data-link-type=dfn href="https://www.w3.org/TR/selectors4/#child-combinator" title="child combinator">child combinator</a> can be used, like <span class=css data-link-type=maybe title="::content > div">::content > div</span>, which will exclude <span class=css data-link-type=maybe title=#four>#four</span> as it’s not treated as a child of the <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element. <p class=note> Note: Note that a selector like <span class=css data-link-type=maybe title="::content div">::content div</span> is equivalent to <span class=css data-link-type=maybe title="*::content div">*::content div</span>, where the <span class=css data-link-type=maybe title=*>*</span> selects many more elements that just the <a data-link-type=element title=content>content</a> element. However, since only the <a data-link-type=element title=content>content</a> element has a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>, it’s the only element that has a <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element as well. </div> <h4 class="heading settled heading" data-level=3.2.4 id=deep-combinator><span class=secno>3.2.4 </span><span class=content> Selecting Through Shadows: the <a class=css data-link-type=maybe href=#selectordef-deep title=/deep/>/deep/</a> combinator</span><a class=self-link href=#deep-combinator></a></h4> <p> When a <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-deep>/deep/<a class=self-link href=#selectordef-deep></a></dfn> combinator is encountered in a selector, replace every element in the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#selector-match-list title="selector match list">selector match list</a> with every element reachable from the original element by traversing any number of child lists or shadow trees. <div class=example> For example, say you had a component with a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> like the following: <pre> <x-foo> <"shadow tree"> <div> <span id="not-top">...</span> </div> <span id="top">...</span> <x-bar> <"shadow tree"> <span id="nested">...</span> </> </x-bar> </> </x-foo> </pre> <p> For a stylesheet in the outer document, the selector <span class=css data-link-type=maybe title="x-foo /deep/ span">x-foo /deep/ span</span> selects all three of <code><span></code> elements: <span class=css data-link-type=maybe title=#top>#top</span>, <span class=css data-link-type=maybe title=#not-top>#not-top</span>, <em>and</em> <span class=css data-link-type=maybe title=#nested>#nested</span>. </div> <p class=issue id=issue-250ee37f><a class=self-link href=#issue-250ee37f></a> This is basically a super-descendant combinator. If the descendant combinator had a real glyph, it would potentially be interesting to just double it. Maybe we can give the descendant combinator a pseudonym of <span class=css data-link-type=maybe title=">>">>></span>, as it itself is a super-child combinator? Then <a class=css data-link-type=maybe href=#selectordef-deep title=/deep/>/deep/</a> could be spelled <span class=css data-link-type=maybe title=">>>">>>></span> <h3 class="heading settled heading" data-level=3.3 id=shadow-cascading><span class=secno>3.3 </span><span class=content> Shadow Cascading & Inheritance</span><a class=self-link href=#shadow-cascading></a></h3> <h4 class="heading settled heading" data-level=3.3.1 id=cascading><span class=secno>3.3.1 </span><span class=content> Cascading</span><a class=self-link href=#cascading></a></h4> <p> To address the desired cascading behavior of rules targetting elements in shadow roots, this specification extends the <a href=http://dev.w3.org/csswg/css-cascade/#cascading>cascade order</a> defined in the Cascade specification. <a data-biblio-type=normative data-link-type=biblio href=#css3cascade title=css3cascade>[CSS3CASCADE]</a> <p> An additional cascade criteria must be added, between Origin and Scope, called Shadow Tree. <p> <ul> <li> When comparing two declarations, if one of them is in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> and the other is in a document that contains that <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>, then for normal rules the declaration from the outer document wins, and for important rules the declaration from the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> wins. <p class=note> Note: This is the <em>opposite</em> of how scoped styles work. <li> When comparing two declarations, if both are in <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> with the same <a data-link-type=dfn href=#host-element0 title="host element">host element</a>, then for normal rules the declaration from the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> that was created most recently wins, and for important rules the declaration from the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> that was created less recently wins. </ul> <p> When calculating <a href=http://dev.w3.org/csswg/css-cascade/#cascade-order>Order of Appearance</a>, the tree of trees, defined by the Shadow DOM specification, is used to calculate ordering. <h4 class="heading settled heading" data-level=3.3.2 id=inheritance><span class=secno>3.3.2 </span><span class=content> Inheritance</span><a class=self-link href=#inheritance></a></h4> <p> The <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> inherit from their <a data-link-type=dfn href=#host-element0 title="host element">host element</a>. <p> The elements in a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> inherit from the parent of the <a data-link-type=element title=content>content</a> element they are ultimately distributed to, rather than from their normal parent. <h2 class="heading settled heading" data-level=4 id=fragment-scoping><span class=secno>4 </span><span class=content> Fragmented Styling</span><a class=self-link href=#fragment-scoping></a></h2> <p> Fragmented content can be styled differently based on which line, column, page, region, etc. it appears in. This is done by using an appropriate <dfn data-dfn-type=dfn data-export="" id=fragment-pseudo-element>fragment pseudo-element<a class=self-link href=#fragment-pseudo-element></a></dfn>, which allows targetting individual fragments of an element rather than the entire element. <div class=example> In our example, the designer wants to make text flowing into #region1 dark blue and bold. This design can be expressed as shown below. <pre>#region1::region p { color: #0C3D5F; font-weight: bold; } </pre> <p> The <span class=css data-link-type=maybe title=::region>::region</span> pseudo-element is followed by a <span class=css data-link-type=maybe title=p>p</span> relative selector in this example. The color and font-weight declarations will apply to any fragments of paragraphs that are displayed in <span class=css data-link-type=maybe title=#region1>#region1</span>. The following figure shows how the rendering changes if we apply this styling specific to <span class=css data-link-type=maybe title=#region1>#region1</span>. Note how less text fits into this box now that the <a class=property data-link-type=propdesc href="https://www.w3.org/TR/css-fonts-3/#propdef-font-weight" title=font-weight>font-weight</a> is bold instead of normal.</p> <figure> <img alt="Illustrate how changing region styling affects the flow of content." src=images/region-styling.png width=450> <figcaption>Different rendering with a different region styling</figcaption> </figure> </div> <p class=note> Note: This feature is an extension of <span class=css data-link-type=maybe title=::first-line>::first-line</span> styling. <h3 class="heading settled heading" data-level=4.1 id=the-region-pseudo-element><span class=secno>4.1 </span><span class=content> Region-based Styling: the <span class=css data-link-type=maybe title=::region>::region</span> pseudo-element</span><a class=self-link href=#the-region-pseudo-element></a></h3> <div class=issue id=issue-f778a2c0><a class=self-link href=#issue-f778a2c0></a> Extend this to specify: <ul> <li><span class=css data-link-type=maybe title="<region-element-selector>::region"><region-element-selector>::region</span> <li><span class=css data-link-type=maybe title="<paginated-element-selector>::page(<page-selector>)"><paginated-element-selector>::page(<page-selector>)</span> <li><span class=css data-link-type=maybe title="<multicol-element>::column(<anb>)"><multicol-element>::column(<AnB>)</span> <li><span class=css data-link-type=maybe title="<fragmented-element-selector>::nth-fragment(<anb>)"><fragmented-element-selector>::nth-fragment(<AnB>)</span> <li><span class=css data-link-type=maybe title=::first-line>::first-line</span> </ul> </div> <p>A ::region pseudo-element represents a relationship between a selector that matches a <span>CSS Region</span>, and a relative selector that matches some named flow content. This allows style declarations to be applied to fragments of named flow content flowing into particular regions.</p> <pre><region selector>::region <content selector> { ... CSS styling declarations ... } </pre> <p>When the ::region pseudo-element is appended to a <a href="https://www.w3.org/TR/css3-selectors/#selector-syntax">selector</a> that matches one or more <span title="CSS Region">CSS Regions</span>, this creates a 'flow fragment' selector. The flow fragment selector specifies which range of elements in the flow can be matched by the relative selector. The relative selector can match elements in the range(s) (see <a data-biblio-type=normative data-link-type=biblio href=#dom title=dom>[DOM]</a>) of the named flow that are displayed fully or partially in the selected region(s).</p> <p>Elements that are fully or partially in the flow fragment range may match the relative selector. However, the style declarations only apply to the fragment of the element that is displayed in the corresponding region(s).</p> <p>Only a limited list of properties apply to a ::region pseudo-element:</p> <p class=issue id=issue-9b00b7af><a class=self-link href=#issue-9b00b7af></a> Either this list should be all functionally inheritable properties, or all properties. Why is it a seemingly-arbitrary subset of all properties, including box properties? <ol> <li><a href="https://www.w3.org/TR/CSS2/fonts.html">font properties</a></li> <li><a href="https://www.w3.org/TR/CSS2/colors.html">color property</a></li> <li><a href="https://www.w3.org/TR/css3-color/#transparency">opacity property</a></li> <li><a href="https://www.w3.org/TR/css3-background/#backgrounds">background property</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css3-text/#word-spacing" title=word-spacing>word-spacing</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css3-text/#letter-spacing" title=letter-spacing>letter-spacing</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css-text-decor-3/#text-decoration" title=text-decoration>text-decoration</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css3-text/#text-transform" title=text-transform>text-transform</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/CSS21/visudet.html#propdef-line-height" title=line-height>line-height</a></li> <li><a href="https://www.w3.org/TR/css3-text/#justification">alignment and justification properties</a></li> <li><a href="https://www.w3.org/TR/css3-background/#borders">border properties</a></li> <li><a href="https://www.w3.org/TR/css3-background/#corners">rounded corner properties</a></li> <li><a href="https://www.w3.org/TR/css3-background/#border-images">border images properties</a></li> <li><a href="https://www.w3.org/TR/CSS2/box.html#margin-properties">margin properties</a></li> <li><a href="https://www.w3.org/TR/CSS2/box.html#padding-properties">padding properties</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css-text-decor-3/#text-shadow" title=text-shadow>text-shadow</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css3-background/#box-shadow" title=box-shadow>box-shadow</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/css3-break/#box-decoration-break" title=box-decoration-break>box-decoration-break</a></li> <li><a class=property data-link-type=propdesc href="https://www.w3.org/TR/CSS21/visudet.html#propdef-width" title=width>width</a></li> </ol> <div class=example id=region-style-example><a class=self-link href=#region-style-example></a> <p>In the following example, the <span>named flow</span> “article-flow” flows into “region-1” and “region-2”.</p> <pre><style> #div-1 { <strong>flow-into: article-flow;</strong> } #region-1, #region-2 { <strong>flow-from: article-flow;</strong> } /* region styling */ <strong>#region-1::region p </strong> { margin-right: 5em; } </style> <body> <div id="div-1"> <p id="p-1">...</p> <p id="p-2">...</p> </div> <div id="region-1"></div> <div id="region-2"></div> </body> </pre> <div id=region_styling_illustration> <img alt="Example showing how a named flow content fits into regions to illustrate region styling." id=region_styling_img_2 src=images/region-styling-2.png> <p> <ul class=swatch-list> <li><span class=swatch style=background:#1C75BC> </span>div div-1</li> <li><span class=swatch style=background:crimson> </span>paragraph p-1</li> <li><span class=swatch style=background:white> </span>paragraph p-2</li> <li><span class=swatch style=background:#E6E7E8> </span>range of flow that fits into region-1</li> <li><span class=swatch style=background:#BCBEC0> </span>range of flow that fits into region-2</li> </ul> </div> <p>The region styling applies to flow content that fits in <span class=css data-link-type=maybe title=region-1>region-1</span>. The relative selector matches <span class=css data-link-type=maybe title=p-1>p-1</span> and <span class=css data-link-type=maybe title=p-2>p-2</span> because these paragraphs flow into <span class=css data-link-type=maybe title=region-1>region-1</span>. Only the fragment of <span class=css data-link-type=maybe title=p-2>p-2</span> that flows into <span class=css data-link-type=maybe title=region-1>region-1</span> is styled with the pseudo-element.</p> </div> <p>All of the selectors in a ::region pseudo-element contribute to its <a href="https://www.w3.org/TR/css3-selectors/#specificity">specificity</a>. So the specificity of the ::region pseudo-element in the example above would combine the id selector’s specificity with the specificity of the type selector, resulting in a specificity of 101.</p> <p>Selectors that match a given element or element fragment (as described above), participate in the <a href="https://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascading-order">CSS Cascading order</a> as defined in <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.</p> <div> Region styling does not apply to nested regions. For example, if a region <span class=css data-link-type=maybe title=a>A</span> receives content from a flow that contains region <span class=css data-link-type=maybe title=b>B</span>, the content that flows into <span class=css data-link-type=maybe title=b>B</span> does not receive the region styling specified for region <span class=css data-link-type=maybe title=a>A</span>. </div> <p class=issue id=issue-5bff6297><a class=self-link href=#issue-5bff6297></a> We’ll need some way to query the styles of a fragment in a particular region. <code>getComputedStyle()</code> isn’t enough, because an element can exist in multiple regions, for example, with each fragment receiving different styles. <h2 class="no-ref no-num heading settled heading" id=conformance><span class=content> Conformance</span><a class=self-link href=#conformance></a></h2> <h3 class="no-ref heading settled heading" id=conventions><span class=content> Document conventions</span><a class=self-link href=#conventions></a></h3> <p>Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification. <p>All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. <a data-biblio-type=normative data-link-type=biblio href=#rfc2119 title=rfc2119>[RFC2119]</a></p> <p>Examples in this specification are introduced with the words "for example" or are set apart from the normative text with <code>class="example"</code>, like this: <div class=example> <p>This is an example of an informative example.</p> </div> <p>Informative notes begin with the word "Note" and are set apart from the normative text with <code>class="note"</code>, like this: <p class=note>Note, this is an informative note.</p> <h3 class="no-ref heading settled heading" id=conformance-classes><span class=content> Conformance classes</span><a class=self-link href=#conformance-classes></a></h3> <p>Conformance to this specification is defined for three conformance classes: <dl> <dt>style sheet <dd>A <a href="https://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS style sheet</a>. <dt>renderer <dd>A <a href="https://www.w3.org/TR/CSS21/conform.html#user-agent">UA</a> that interprets the semantics of a style sheet and renders documents that use them. <dt>authoring tool <dd>A <a href="https://www.w3.org/TR/CSS21/conform.html#user-agent">UA</a> that writes a style sheet. </dl> <p>A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module. <p>A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.) <p>An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module. <h3 class="no-ref heading settled heading" id=partial><span class=content> Partial implementations</span><a class=self-link href=#partial></a></h3> <p>So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers <strong>must</strong> treat as invalid (and <a href="https://www.w3.org/TR/CSS21/conform.html#ignore">ignore as appropriate</a>) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents <strong>must not</strong> selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.</p> <h3 class="no-ref heading settled heading" id=experimental><span class=content> Experimental implementations</span><a class=self-link href=#experimental></a></h3> <p>To avoid clashes with future CSS features, the CSS2.1 specification reserves a <a href="https://www.w3.org/TR/CSS21/syndata.html#vendor-keywords">prefixed syntax</a> for proprietary and experimental extensions to CSS. <p>Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft. </p> <h3 class="no-ref heading settled heading" id=testing><span class=content> Non-experimental implementations</span><a class=self-link href=#testing></a></h3> <p>Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec. <p>To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group. <p>Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at <a href="https://www.w3.org/Style/CSS/Test/">http://www.w3.org/Style/CSS/Test/</a>. Questions should be directed to the <a href=http://lists.w3.org/Archives/Public/public-css-testsuite>public-css-testsuite@w3.org</a> mailing list. <h2 class="no-num no-ref heading settled heading" id=references><span class=content> References</span><a class=self-link href=#references></a></h2> <h3 class="no-num no-ref heading settled heading" id=normative><span class=content> Normative References</span><a class=self-link href=#normative></a></h3> <div data-fill-with=normative-references><dl><dt id=css21 title=CSS21><a class=self-link href=#css21></a>[CSS21]<dd>Bert Bos; et al. <a href="https://www.w3.org/TR/2011/REC-CSS2-20110607">Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification</a>. 7 June 2011. W3C Recommendation. URL: <a href="https://www.w3.org/TR/2011/REC-CSS2-20110607">http://www.w3.org/TR/2011/REC-CSS2-20110607</a><dt id=css3cascade title=CSS3CASCADE><a class=self-link href=#css3cascade></a>[CSS3CASCADE]<dd>Håkon Wium Lie; Elika J. Etemad; Tab Atkins Jr.. <a href="https://www.w3.org/TR/2013/CR-css-cascade-3-20131003/">CSS Cascading and Inheritance Level 3</a>. 3 October 2013. W3C Candidate Recommendation. (Work in progress.) URL: <a href="https://www.w3.org/TR/2013/CR-css-cascade-3-20131003/">http://www.w3.org/TR/2013/CR-css-cascade-3-20131003/</a><dt id=dom title=DOM><a class=self-link href=#dom></a>[DOM]<dd>Anne van Kesteren; Aryeh Gregor; Ms2ger. <a href="https://dom.spec.whatwg.org/">DOM Living Standard</a>. WHATWG Living Standard. (Work in progress.) URL: <a href="https://dom.spec.whatwg.org/">http://dom.spec.whatwg.org/</a><dt id=rfc2119 title=RFC2119><a class=self-link href=#rfc2119></a>[RFC2119]<dd>S. Bradner. <a href=http://www.ietf.org/rfc/rfc2119.txt>Key words for use in RFCs to Indicate Requirement Levels</a>. URL: <a href=http://www.ietf.org/rfc/rfc2119.txt>http://www.ietf.org/rfc/rfc2119.txt</a></dl></div> <h3 class="no-num no-ref heading settled heading" id=informative><span class=content> Informative References</span><a class=self-link href=#informative></a></h3> <div data-fill-with=informative-references><dl><dt id=html title=HTML><a class=self-link href=#html></a>[HTML]<dd>Ian Hickson. <a href="https://www.whatwg.org/specs/web-apps/current-work/multipage/">HTML</a>. Living Standard. URL: <a href="https://www.whatwg.org/specs/web-apps/current-work/multipage/">http://www.whatwg.org/specs/web-apps/current-work/multipage/</a><dt id=selectors4 title=SELECTORS4><a class=self-link href=#selectors4></a>[SELECTORS4]<dd>Elika J. Etemad; Tab Atkins Jr.. <a href="https://www.w3.org/TR/2013/WD-selectors4-20130502/">Selectors Level 4</a>. 2 May 2013. W3C Working Draft. (Work in progress.) URL: <a href="https://www.w3.org/TR/2013/WD-selectors4-20130502/">http://www.w3.org/TR/2013/WD-selectors4-20130502/</a></dl></div> <h2 class="no-num no-ref heading settled heading" id=index><span class=content> Index</span><a class=self-link href=#index></a></h2> <div data-fill-with=index><ul class=indexlist> <li>active shadow tree, <a href=#active-shadow-tree title="section 3">3</a> <li>::content, <a href=#selectordef-content title="section 3.2.3">3.2.3</a> <li>/deep/, <a href=#selectordef-deep title="section 3.2.4">3.2.4</a> <li>distribution list, <a href=#distribution-list title="section 3">3</a> <li>fragment pseudo-element, <a href=#fragment-pseudo-element title="section 4">4</a> <li>:host(), <a href=#selectordef-host title="section 3.2.1">3.2.1</a> <li>:host, <a href=#selectordef-host0 title="section 3.2.1">3.2.1</a> <li>:host-context(), <a href=#selectordef-host-context title="section 3.2.1">3.2.1</a> <li>host element, <a href=#host-element0 title="section 3">3</a> <li>insertion point, <a href=#insertion-point title="section 3">3</a> <li>@scope, <a href=#at-ruledef-scope title="section 2.1.2">2.1.2</a> <li>::shadow, <a href=#selectordef-shadow title="section 3.2.2">3.2.2</a> <li>shadow host, <a href=#shadow-host title="section 3">3</a> <li>shadow root, <a href=#shadow-root title="section 3">3</a> <li>shadow tree, <a href=#shadow-tree title="section 3">3</a> <li>top-level element, <a href=#top-level-element title="section 3">3</a> </ul></div> <h2 class="no-num no-ref heading settled heading" id=property-index><span class=content> Property index</span><a class=self-link href=#property-index></a></h2> <div data-fill-with=property-index><p>No properties defined.</div> <h2 class="no-num heading settled" id=issues-index><span class=content>Issues Index</span><a class=self-link href=#issues-index></a></h2><div style="counter-reset: issue"><div class=issue> This rule makes it very easy for authors to create scoped style sheets, which could affect the optimization strategies for implementing scoped styles. <a href=#issue-5f568f10> ↵ </a></div><div class=issue> If multiple <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rules apply to an element, should they be cascaded by specificity? <a href=#issue-5c7571b6> ↵ </a></div><div class=issue> This would be defined similarly to <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a>, but matching the ancestors of the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a> instead. <p> However, since for scoped stylesheets you may want the ability to match complex selectors against the outside tree, rather than a single compound selector, we may want to instead use a more general mechanism that doesn’t syntactically invert the order of tree elements. <p> Possible ideas: <pre>:scope-context(<a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>) div {...} scope(<a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>) div {...} \scope <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a>\ div {...} <a class="production css-code" data-link-type=type href="https://www.w3.org/TR/selectors4/#ltselector" title="<selector>"><selector></a> \scope\ div {...} </pre> <p> This functionality would replace <span class=css data-link-type=maybe title=@global>@global</span>, which is a poor excuse for a selector. </p><a href=#issue-aecbd194> ↵ </a></div> <div class=issue> This section is still under discussion. Feedback and advice on intuitive syntax for the following functionality would be appreciated. <a href=#issue-dea392ae> ↵ </a></div><div class=issue> <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> is a confusingly general name for something that is specific to the projected content of a shadow tree. <a href=#issue-1b6118ae> ↵ </a></div><div class=issue> This is basically a super-descendant combinator. If the descendant combinator had a real glyph, it would potentially be interesting to just double it. Maybe we can give the descendant combinator a pseudonym of <span class=css data-link-type=maybe title=">>">>></span>, as it itself is a super-child combinator? Then <a class=css data-link-type=maybe href=#selectordef-deep title=/deep/>/deep/</a> could be spelled <span class=css data-link-type=maybe title=">>>">>>></span> <a href=#issue-250ee37f> ↵ </a></div><div class=issue> Extend this to specify: <ul> <li><span class=css data-link-type=maybe title="<region-element-selector>::region"><region-element-selector>::region</span> <li><span class=css data-link-type=maybe title="<paginated-element-selector>::page(<page-selector>)"><paginated-element-selector>::page(<page-selector>)</span> <li><span class=css data-link-type=maybe title="<multicol-element>::column(<anb>)"><multicol-element>::column(<AnB>)</span> <li><span class=css data-link-type=maybe title="<fragmented-element-selector>::nth-fragment(<anb>)"><fragmented-element-selector>::nth-fragment(<AnB>)</span> <li><span class=css data-link-type=maybe title=::first-line>::first-line</span> </ul> <a href=#issue-f778a2c0> ↵ </a></div> <div class=issue> Either this list should be all functionally inheritable properties, or all properties. Why is it a seemingly-arbitrary subset of all properties, including box properties? <a href=#issue-9b00b7af> ↵ </a></div><div class=issue> We’ll need some way to query the styles of a fragment in a particular region. <code>getComputedStyle()</code> isn’t enough, because an element can exist in multiple regions, for example, with each fragment receiving different styles. <a href=#issue-5bff6297> ↵ </a></div></div><script src="https://www.w3.org/scripts/TR/fixup.js"></script>