Skip to content

Commit 136029a

Browse files
authored
[css-conditional-5] Defined @supports-condition #12622 (#12935)
1 parent 433051c commit 136029a

File tree

2 files changed

+118
-15
lines changed

2 files changed

+118
-15
lines changed

css-cascade-5/Overview.bs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Importing Style Sheets: the ''@import'' rule</h2>
129129
as if they were written literally into the stylesheet at the point of the ''@import''.
130130

131131
Any ''@import'' rules must precede all other valid at-rules and style rules in a style sheet
132-
(ignoring ''@charset'' and <a href="#layer-empty"><css>@layer</css> statement</a> rules)
132+
(ignoring ''@charset'', ''@supports-condition'', and <a href="#layer-empty"><css>@layer</css> statement</a> rules)
133133
and must not have any other valid at-rules or style rules between it and previous ''@import'' rules,
134134
or else the ''@import'' rule is invalid.
135135
The syntax of ''@import'' is:

css-conditional-5/Overview.bs

Lines changed: 117 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Editor: L. David Baron, Google https://www.google.com/, https://dbaron.org/, w3c
1313
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
1414
Editor: Chris Lilley, W3C, https://svgees.us/, w3cid 1438
1515
Editor: Miriam E. Suzanne, Invited Expert, https://www.miriamsuzanne.com/who/, w3cid 117151
16+
Editor: Lea Verou, Invited Expert, https://lea.verou.me/about, w3cid 52258
1617
Abstract: This module contains the features of CSS
1718
for conditional processing of parts of style sheets,
1819
based on capabilities of the processor or the environment
@@ -78,7 +79,7 @@ Introduction</h2>
7879

7980
CSS Conditional Level 5 extends
8081
the ''@supports'' rule and [=supports query=] syntax
81-
to allow testing for supported font technologies.
82+
to allow testing for custom support conditions as well as supported [=at-rules=] and font technologies.
8283

8384
It also adds an ''@when'' rule,
8485
which generalizes the concept of a conditional rule.
@@ -117,12 +118,20 @@ Extensions to the ''@supports'' rule</h2>
117118
<dfn>&lt;supports-feature></dfn> = <<supports-selector-fn>>
118119
| <<supports-font-tech-fn>> | <<supports-font-format-fn>>
119120
| <<supports-at-rule-fn>>
120-
| <<supports-decl>>
121+
| <<supports-decl>>
122+
<dfn>&lt;supports-decl></dfn> = ( [ <<declaration>> | <<supports-condition-name>> ] )
121123
<dfn>&lt;supports-font-tech-fn></dfn> = font-tech( <<font-tech>> )
122124
<dfn>&lt;supports-font-format-fn></dfn> = font-format( <<font-format>> )
123125
<dfn>&lt;supports-at-rule-fn></dfn> = at-rule( <<at-keyword-token>> )
124126
</pre>
125127

128+
: <<supports-condition-name>>
129+
::
130+
The result is true if the UA
131+
<a href="#dfn-supports-condition-name">supports the named condition</a>.
132+
If the name is not recognized,
133+
the result is false.
134+
126135
: <<supports-font-tech-fn>>
127136
::
128137
The result is true if the UA
@@ -148,8 +157,6 @@ Extensions to the definition of support</h3>
148157
Font techs and formats</h4>
149158

150159
<wpt>
151-
at-supports-font-format-001.html
152-
at-supports-font-tech-001.html
153160
js/CSS-supports-L5.html
154161
</wpt>
155162

@@ -179,6 +186,13 @@ At-rules</h4>
179186
Note: Because ''@charset'' is not a valid [=at-rule=],
180187
it is not considered to be supported under this definition.
181188

189+
<h4 id="support-definition-supports-condition-name">
190+
Named conditions</h4>
191+
192+
A CSS processor is considered to
193+
<dfn export for=CSS id="dfn-supports-condition-name">support a named condition</dfn>
194+
when the related [=named supports condition=] returns true.
195+
182196
<h2 id="when-rule">
183197
Generalized Conditional Rules: the ''@when'' rule</h2>
184198

@@ -1743,13 +1757,86 @@ Container Relative Lengths: the ''cqw'', ''cqh'', ''cqi'', ''cqb'', ''cqmin'', '
17431757
</div>
17441758

17451759

1760+
<h2 id="supports-condition-rule">
1761+
Defining Custom Support Queries: the ''@supports-condition'' rule</h2>
1762+
1763+
The <dfn at-rule id="at-ruledef-supports-condition">@supports-condition</dfn> [=at-rule=] is a [=conditional group rule=] that allows authors to define and name a [=supports query=] for later reuse,
1764+
creating a <dfn export>named supports condition</dfn>.
1765+
This enables complex or frequently-used feature queries to be referenced by name,
1766+
improving maintainability and readability.
1767+
1768+
<pre class="prod def">
1769+
@supports-condition <<supports-condition-name>> {
1770+
<<block-contents>>
1771+
}
1772+
</pre>
1773+
1774+
Where <dfn><<supports-condition-name>></dfn> is an <<extension-name>> that defines the name of the supports query.
1775+
1776+
Anything inside the block is evaluated to test whether the user agent supports the features used.
1777+
The contents do not have any effect on the document's rendering.
1778+
1779+
Once defined, the named supports condition can be used in subsequent ''@supports'' or ''@when'' conditions.
1780+
1781+
Multiple ''@supports-condition'' rules with the same name in a style sheet are invalid and must be ignored.
1782+
1783+
<div class="example">
1784+
For example, we can define a supports query checking multiple properties at once:
1785+
<pre class="lang-css">
1786+
@supports-condition --thicker-underlines {
1787+
text-decoration-thickness: 0.2em;
1788+
text-underline-offset: 0.3em;
1789+
}
1790+
1791+
/* Equivalent to (text-decoration-thickness: 0.2em) and (text-underline-offset: 0.3em) */
1792+
@supports (--thicker-underlines) {
1793+
a {
1794+
text-decoration: underline;
1795+
text-decoration-thickness: 0.2em;
1796+
text-underline-offset: 0.3em;
1797+
}
1798+
}
1799+
</pre>
1800+
</div>
1801+
1802+
''@supports-condition'' rules are allowed before ''@import'' and ''@namespace'' rules (after the ''@charset'' rule, if any).
1803+
1804+
<div class="example">
1805+
As support queries can contain arbitrary declarations,
1806+
they can be used to detect support for complex features such as nesting:
1807+
<pre class="lang-css">
1808+
@supports-condition --nesting {
1809+
& { }
1810+
}
1811+
1812+
@import url("nested-styles.css") supports(--nesting);
1813+
</pre>
1814+
</div>
1815+
1816+
<div class="example">
1817+
Support queries can also be used to detect support for at-rules:
1818+
<pre class="lang-css">
1819+
@supports-condition --stuck-container-feature {
1820+
@container scroll-state(stuck: top) { }
1821+
}
1822+
1823+
@supports (--stuck-container-feature) {
1824+
div { border-color: navy; }
1825+
}
1826+
</pre>
1827+
</div>
1828+
1829+
Issue: The name of the at-rule is under discussion.
1830+
Alternatives include ''@supports-query'', ''@supports-test'', and ''@custom-supports''.
1831+
The name should be consistent with the one chosen for custom media queries.
1832+
17461833
<h2 id="apis">APIs</h2>
17471834

17481835

17491836
<h3 id="the-csscontainerrule-interface">
17501837
The <code>CSSContainerRule</code> interface</h3>
17511838

1752-
The {{CSSContainerRule}} interface represents a ''@container'' rule.
1839+
The {{CSSContainerRule}} interface represents an ''@container'' rule.
17531840

17541841
<pre class='idl'>
17551842
[Exposed=Window]
@@ -1805,6 +1892,23 @@ The <code>CSSContainerRule</code> interface</h3>
18051892
When measuring layout sizes, it behaves Similar to <code>resizeObserver</code>,
18061893
but it provides the additional Container Query syntax and features.
18071894

1895+
<h3 id="the-csssupportscondition-interface">
1896+
The <code>CSSSupportsConditionRule</code> interface</h3>
1897+
1898+
The {{CSSSupportsConditionRule}} interface represents an ''@supports-condition'' rule.
1899+
1900+
<pre class='idl'>
1901+
[Exposed=Window]
1902+
interface CSSSupportsConditionRule : CSSGroupingRule {
1903+
readonly attribute CSSOMString name;
1904+
};
1905+
</pre>
1906+
1907+
<dl class='idl-attributes'>
1908+
<dt><code>name</code> of type <code>CSSOMString</code>
1909+
<dd>This attribute is the name of the [=named supports condition=].
1910+
</dl>
1911+
18081912
<h2 class=no-num id="security">Security Considerations</h2>
18091913

18101914
No security issues have been raised against this document
@@ -1835,18 +1939,17 @@ Changes since the <a href="https://www.w3.org/TR/2024/WD-css-conditional-5-20241
18351939
</h3>
18361940

18371941
<ul>
1838-
<li>
1839-
Dimensional query containers no longer apply layout containment
1840-
(<a href="https://github.com/w3c/csswg-drafts/pull/10544">#10544</a>)
1841-
</li>
1942+
<li>Dimensional query containers no longer apply layout containment
1943+
(<a href="https://github.com/w3c/csswg-drafts/pull/10544">#10544</a>)</li>
18421944
<li>
18431945
Extended [=supports queries=] to express [=at-rule=] capabilities
18441946
via ''at-rule()''.
18451947
(<a href="https://github.com/w3c/csswg-drafts/issues/2463">#2463</a>,
18461948
<a href="https://github.com/w3c/csswg-drafts/issues/6966">#6966</a>,
18471949
<a href="https://github.com/w3c/csswg-drafts/issues/11116">#11116</a>,
1848-
<a href="https://github.com/w3c/csswg-drafts/issues/11117">#11117</a>)
1849-
</li>
1950+
<a href="https://github.com/w3c/csswg-drafts/issues/11117">#11117</a>)</li>
1951+
<li>Added ''@supports-condition'' at-rule and related {{CSSSupportsConditionRule}} interface.
1952+
(<a href="https://github.com/w3c/csswg-drafts/issues/12622">#12622</a>)</li>
18501953
</ul>
18511954

18521955
<h3 id="changes-20240723" class="no-num">
@@ -1855,7 +1958,7 @@ Changes since the <a href="https://www.w3.org/TR/2024/WD-css-conditional-5-20240
18551958

18561959
<ul>
18571960
<!-- To 31 Oct 2024 -->
1858-
<li>Add ''@container/stuck/none''-keywords to scroll-state() features (<a href="https://github.com/w3c/csswg-drafts/pull/10874">#10874</a>)</li>
1961+
<li>Added ''@container/stuck/none''-keywords to scroll-state() features (<a href="https://github.com/w3c/csswg-drafts/pull/10874">#10874</a>)</li>
18591962
<li>Added container-type:scroll-state, and scroll-state() queries for stuck, snapped, and scrollable features
18601963
(<a href="https://github.com/w3c/csswg-drafts/issues/6402#issuecomment-1812973013">#6402</a>,
18611964
<a href="https://github.com/w3c/csswg-drafts/issues/10784#issuecomment-2379901508">#10784</a>,
@@ -1874,7 +1977,7 @@ Changes since the <a href="https://www.w3.org/TR/2021/WD-css-conditional-5-20211
18741977
<li>Imported the definitions of &lt;font-format> and &lt;font-tech> from CSS Fonts 4, rather than duplicating them in this specification (<a href="https://github.com/w3c/csswg-drafts/issues/8110">#8110</a>)</li>
18751978
<li> Updated to use the new parsing algorithm names and block production names</li>
18761979
<li>Corrected a typo in the grammar of &lt;font-format></li>
1877-
<li>Corrected extra spaces in the font-tech and font-format productions (<a href="https://github.com/w3c/csswg-drafts/issues/7369">#7369</a> )</li>
1980+
<li>Corrected extra spaces in the font-tech and font-format productions (<a href="https://github.com/w3c/csswg-drafts/issues/7369">#7369</a>)</li>
18781981
</ul>
18791982

18801983
<h3 id="changes-from-L4" class="no-num">
@@ -1889,6 +1992,7 @@ Additions since Level 4</h3>
18891992
<li>Moved Container Queries from [[CSS-CONTAIN-3]] to this specification.
18901993
(See also the [[CSS-CONTAIN-3#changes]] for more information
18911994
on the evolution of this feature.)
1995+
<li>Added ''@supports-condition'' at-rule and related {{CSSSupportsConditionRule}} interface.
18921996
</ul>
18931997

18941998
<h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
@@ -2045,7 +2149,6 @@ Additions since Level 4</h3>
20452149
js/CSS-supports-CSSStyleDeclaration.html
20462150
js/CSS-supports-L3.html
20472151
js/CSS-supports-L4.html
2048-
js/CSS-supports-L5.html
20492152
js/CSS-supports-selector-detecting-invalid-in-logical-combinations.html
20502153
js/conditional-CSSGroupingRule.html
20512154
js/supports-conditionText.html

0 commit comments

Comments
 (0)