Title: CSS Conditional Rules Module Level 4
Group: csswg
Shortname: css-conditional
Level: 4
Status: ED
Prepare for TR: no
!Delta Spec: yes
Work Status: Exploring
ED: https://drafts.csswg.org/css-conditional-4/
TR: https://www.w3.org/TR/css-conditional-4/
Previous Version: https://www.w3.org/TR/2022/CR-css-conditional-4-20220217/
Test Suite: https://wpt.fyi/results/css/css-conditional
Implementation Report: https://wpt.fyi/results/css/css-conditional
Editor: L. David Baron, Mozilla https://www.mozilla.org/, https://dbaron.org/, w3cid 15393
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Chris Lilley, W3C, https://svgees.us/, w3cid 1438
Abstract: This module contains the features of CSS
	for conditional processing of parts of style sheets,
	based on capabilities of the processor or the environment
	the style sheet is being applied in.
	It includes and extends the functionality of CSS Conditional 3 [[!css-conditional-3]],
	adding the ability to query support for particular selectors [[SELECTORS-4]]
	through the new 
	''selector()'' notation for [=supports queries=].
Default Highlight: css
WPT Path Prefix: css/css-conditional/
WPT Display: open

Introduction

ISSUE: The features in level 3 are still defined in [[css-conditional-3]] and have not yet been copied here. This level adds extensions to the ''@supports'' rule to allow testing for supported selectors.

Extensions to the ''@supports'' rule

This level of the specification extends the <> syntax as follows:
		<supports-feature> = <> | <>
		<supports-selector-fn> = selector( <> )
	
: <> :: The result is true if the UA supports the selector provided as an argument to the function. at-supports-selector-001.html at-supports-selector-002.html at-supports-selector-003.html at-supports-selector-004.html at-supports-selector-detecting-invalid-in-logical-combinations.html at-supports-selector-file-selector-button.html at-supports-selector-placeholder.html js/CSS-supports-L4.html js/CSS-supports-selector-detecting-invalid-in-logical-combinations.html
This example tests whether the column combinator (||) is supported in selectors, and if so uses it to style particular cells in a table.
		@supports selector(col || td) {
			col.selected || td {
				background: tan;
			}
		}
	
Any namespace prefixes used in a [=conditional group rule=] must have been declared, otherwise they are invalid [[!css-conditional-3]]. This includes namespace prefixes inside the selector function. at-supports-namespace-002.html
This example tries to check that attribute selectors with [=CSS qualified name=]s are supported, but is invalid, because the namespace prefix has not been declared.
		@supports selector(a[xlink|href]) {
			// do something, but fail
			}
		}
	
This example checks that attribute selectors with [=CSS qualified name=]s are supported.
		@namespace x url(http://www.w3.org/1999/xlink);
		@supports selector(a[x|href]) {
			// do something
			}
		}
	

Extensions to the definition of support

A CSS processor is considered to support a CSS selector if it accepts that all aspects of that selector, recursively, (rather than considering any of its syntax to be unknown or invalid) and that selector doesn't contain unknown -webkit- pseudo-elements. Note: Some functional selectors are parsed forgivingly, i.e. if some arguments are unknown/invalid, the selector itself is not invalidated. These are nonetheless unsupported

Security Considerations

No Security issues have been raised against this document

Privacy Considerations

The ''selector()'' function may provide information about the user's software such as its version and whether it is running with non-default settings that enable or disable certain features. This information can also be determined through other APIs. However, the features in this specification are one of the ways this information is exposed on the Web. This information can also, in aggregate, be used to improve the accuracy of fingerprinting of the user.

Acknowledgments

The editors would like to thank all of the contributors to the previous level of this module.

Changes

Changes since the Candidate Recommendation Snapshot of 17 February 2022

Changes since the First Public Working Draft of 3 March 2020

Additions since Level 3