Skip to content

Commit a483e9b

Browse files
committed
[selectors-4][editorial] Finish off the explainer
1 parent 49b31aa commit a483e9b

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

selectors-4/Selectors_4_Explainer.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@ Selectors are a mature and widely deployed way to
1515
select **individual parts** of a (typically HTML) document,
1616
so that they may be **styled** or **manipulated with script**.
1717

18+
```css
19+
a:hover {text-decoration: underline}
20+
```
21+
```js
22+
const matches = document.querySelectorAll("div.note, div.alert");
23+
```
24+
1825
They were further developed in [CSS2.1](https://www.w3.org/TR/CSS2/selector.html#q5.0)
1926
(W3C Recommendation, from 2011)
2027
and in [Selectors 3](https://www.w3.org/TR/selectors-3/)
2128
(W3C Recommendation, 2018).
2229

2330
[Selectors 4](https://www.w3.org/TR/selectors-4/)
2431
is an incremental improvement to previous Selectors specifications,
25-
responding to common user needs.
26-
32+
responding to common user needs
33+
and with a particular focus on selecting **functional, semantic classes** of elements.
2734
It is now widely deployed, stable,
28-
and is being prepared for W3C Recommendation,
29-
while less-mature Selectors have been moved to
35+
and is being _prepared for W3C Recommendation_,
36+
while the less-mature Selectors have been moved to
3037
[Selectors 5](https://www.w3.org/TR/selectors-5/).
3138

32-
However, the Selectors 4 specification
39+
Note that the Selectors 4 specification
3340
is a _complete specification_ of Selectors,
34-
(including material from levels 1 through 3)
41+
(thus, including material from levels 1 through 3)
3542
not a delta. This aids readability.
3643

3744
In view of this widespread use,
3845
this explainer does not address early-review questions
3946
such as general user need or alternatives considered;
40-
instead it motivates the particular changes found in Selectors 4.
47+
instead it motivates the particular changes found in Selectors 4,
48+
many of which have been baseline available for years.
4149

4250
## Why `Selectors` not `CSS Selectors`?
4351

@@ -54,26 +62,38 @@ These are both majority uses, hence the naming of the specification.
5462

5563
- The matches-any [`:is`](https://www.w3.org/TR/selectors-4/#matches) pseudo-class,
5664
formerly called `:matches()`,
57-
has been added to allow stylesheet authors to group functionally related elements,
65+
has been added to allow stylesheet authors to **group functionally related elements**,
5866
such as any element that is either hovered or focussed.
5967
- The specificity-adjusting [`:where()`](https://www.w3.org/TR/selectors-4/#zero-matches) pseudo-class
60-
has been added to construct zero-specificity filters,
68+
has been added to construct **zero-specificity filters**,
6169
which are easy to override,
6270
replacing the many ugly hacks previously required to simulate this
63-
- The relational [`:has()`]() pseudo-class
71+
- The relational [`:has()`]() pseudo-class takes a **selector list** and matches any element tht would match at lest one selector in that list.
6472

65-
### Interactivity and Forms
73+
### Interaction, Input and Forms
6674

6775
- Added the [`:modal`](https://www.w3.org/TR/selectors-4/#modal-state) pseudo-class,
68-
to select elements which exclude interaction with all other elements until dismissed
76+
to select elements which **exclude interaction** with all other elements until dismissed
6977
- Added [`:open`](https://www.w3.org/TR/selectors-4/#open-state)
7078
and [`:popover-open`](https://www.w3.org/TR/selectors-4/#popover-open-state) pseudo-classes,
71-
primarily but not exclusively to use with HTML forms
79+
primarily but not exclusively to use with **HTML forms**
80+
81+
_The following selectors were previously in [CSS Basic UI 3](https://www.w3.org/TR/css-ui-3/)
82+
and have been moved to the main Selectors 4 specification
83+
for ease of reference_
84+
85+
- Added the [`:valid` and `:invalid`](https://www.w3.org/TR/selectors-4/#range-pseudos) pseudo-classes
86+
- Added the [`:user-valid` and `:user-invalid`](https://www.w3.org/TR/selectors-4/#user-pseudos), pseudo-classes. These only match afer **significant user interaction**.
87+
- Added the [`:required` and `:optional`](https://www.w3.org/TR/selectors-4/#opt-pseudos) optionality pseudo-classes
88+
- Added the [`:enabled` and `:disabled`](https://www.w3.org/TR/selectors-4/#enableddisabled) pseudo-classes
89+
- Added the [`:read-only` and `:read-write`](https://www.w3.org/TR/selectors-4/#rw-pseudos) mutability pseudo-classes
90+
- Added the automatic input [`:autofill`](https://www.w3.org/TR/selectors-4/#autofill) pseudo-class
91+
- Added the **selected-option** [`:checked`, `:unchecked` and `:indeterminate`](https://www.w3.org/TR/selectors-4/#checked) pseudo-classes
7292

7393
### Hyperlinking Support
7494

7595
- Added [`:any-link`](https://www.w3.org/TR/selectors-4/#the-any-link-pseudo) to match
76-
any element that acts as the source anchor of a hyperlink
96+
any element that acts as the **source anchor** of a hyperlink
7797

7898
### Clearer Expression of Authorial Intent
7999

@@ -84,40 +104,35 @@ These are both majority uses, hence the naming of the specification.
84104
### Media State
85105

86106
- Added the `:playing`, `:paused` and `:seeking` [media playback state](https://www.w3.org/TR/selectors-4/#video-state) pseudo classes,
87-
to enable selecting on the dynamic state of video elements,
107+
to enable selecting on the **dynamic state of video elements**,
88108
functionality which previously required JavaScript
89109
- Added the `:buffered` and `:stalled`
90110
[media loading state](https://www.w3.org/TR/selectors-4/#media-loading-state) pseudo-classes,
91111
again providing functionality that previously needed JavaScript
92112
- Added the [`:fullscreen`](https://www.w3.org/TR/selectors-4/#fullscreen-state)
93113
and [`:picture-in-picture`](https://www.w3.org/TR/selectors-4/#pip-state) pseudo-classes
94114
- Added the `:muted` and `volume-locked` pseudo-classes
95-
for sound-producing elements
115+
for **sound-producing elements**
96116

97117
### Internationalization Improvements
98118

99119
- Expanded the content language
100120
[`:lang()`](https://www.w3.org/TR/selectors-4/#the-lang-pseudo) pseudo-class
101-
to accept **wildcard matching** and **lists of language codes**
121+
to accept **wildcard matching**, and comma-separated **lists of language codes**
102122
for greater flexibility styling related languages
103123
- Added the content language writing direction
104124
[`dir()`](https://www.w3.org/TR/selectors-4/#the-dir-pseudo) pseudo-class
105-
for convenient styling of left-to-right and righ-to-left content
106-
- Clarified case-insensitive string matching
107-
108-
### Consolidation
109-
110-
Selectors first introduced in
111-
[CSS Basic UI 3](https://www.w3.org/TR/css-ui-3/),
112-
have been moved to the main Selectors 4 specification.
125+
for convenient styling of **left-to-right** and **right-to-left** content
126+
- Clarified **case-insensitive** string matching
127+
- General improvements to closely align with **BCP 47**
113128

114129
## Further reading
115130

116-
For further information on the use of Selectors in CSS
117-
(covering all levels, but with a focus on level 4), see
131+
For further information on the use of Selectors in CSS
132+
(covering all levels, but with a focus on level 4), see
118133
[CSS Selectors](https://css-tricks.com/css-selectors/) on CSS-Tricks.
119134

120135
For selectors in the DOM, see
121136
[NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) on MDN.
122137

123-
The [Horizontal Review of Selectors 4](https://github.com/w3c/csswg-drafts/issues/13469).
138+
The [Horizontal Review of Selectors 4](https://github.com/w3c/csswg-drafts/issues/13469).

0 commit comments

Comments
 (0)