From the W3C standard's definition of pseudo-elements https://www.w3.org/TR/selectors-3/#pseudo-elements:
Pseudo-elements create abstractions about the document tree beyond those specified by the document language. For instance, document languages do not offer mechanisms to access the first letter or first line of an element’s content. Pseudo-elements allow authors to refer to this otherwise inaccessible information.
(My emphasis.)
Why excatly does the document language allow for detection of the first child element (so that :first-child
is a css pseudo-class) but not of the first letter (so that ::first-letter
is a css pseudo-element)? How should this "document language" be understood?
In essence the question is: Why is there a difference in picking the first element in contrast to the first letter? Why can the document language retrieve one but not the other?
I am not asking to the general difference between pseudo classes and pseudo elements, but rather I am asking specifically about why a first letter is conceptually different from a first child element. Other pseudo elements are less confusing: that ::after
and ::before
for example are pseudo elements is fairly obvious, as they relate to a "space" that isn't defined in the html structure. But the first letter is, so therefore the question of why such first letter is still treated differently.