CSS Pseudo-Elements Module Level 4

Editor’s Draft, 22 November 2014

This version:
http://dev.w3.org/csswg/css-pseudo-4/
Latest version:
http://www.w3.org/TR/css-pseudo-4/
Feedback:
www-style@w3.org with subject line “[css-pseudo] … message topic …” (archives)
Editors:
Daniel Glazman (Disruptive Innovations)
fantasai (Invited Expert)
(Adobe Systems Inc.)
Issues List:
Tracked in Editor’s Draft

Abstract

This CSS module defines pseudo-elements, abstract elements that represent portions of the CSS render tree that can be selected and styled.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-pseudo” in the subject, preferably like this: “[css-pseudo] …summary of comment…

This document was produced by the CSS Working Group (part of the Style Activity).

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures 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 Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 August 2014 W3C Process Document.

Table of Contents

1. Introduction

This section is informative.

Pseudo-elements represent abstract elements of the document beyond those elements explicitly created by the document language. Since they are not restricted to fitting into the document tree, the can be used the select and style portions of the document that do not necessarily map to the document’s tree structure. For instance, the ::first-line pseudo-element can select content on the first formatted line of an element after text wrapping, allowing just that line to be styled differently from the rest of the paragraph.

Each pseudo-element is associated with an originating element and has syntax of the form ::name-of-pseudo. This module defines the pseudo-elements that exist in CSS and how they can be styled. For more information on pseudo-elements in general, and on their syntax and interaction with other selectors, see [SELECTORS4].

2. Typographic Pseudo-elements

2.1. The ::first-line pseudo-element

The ::first-line pseudo-element describes the contents of the first formatted line of its originating element.

The rule below means “change the letters of the first line of every p element to uppercase”:
p::first-line { text-transform: uppercase }

The selector p::first-line does not match any real document element. It does match a pseudo-element that conforming user agents will insert at the beginning of every p element.

Note: Note that the length of the first line depends on a number of factors, including the width of the page, the font size, etc.

For example, given an ordinary HTML [HTML5] paragraph such as:
<P>This is a somewhat long HTML
paragraph that will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>

The lines might be broken as follows:

THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
will be broken into several lines. The first
line will be identified by a fictional tag
sequence. The other lines will be treated as
ordinary lines in the paragraph.

This paragraph might be “rewritten” by user agents to include a fictional tag sequence to represent ::first-line. This fictional tag sequence helps to show how properties are inherited.

<P><P::first-line> This is a somewhat long HTML
paragraph that </P::first-line> will be broken into several
lines. The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>

If a pseudo-element breaks up a real element, the desired effect can often be described by a fictional tag sequence that closes and then re-opens the element.

Thus, if we mark up the previous paragraph with a span element encompassing the first sentence:
<P><SPAN class="test"> This is a somewhat long HTML
paragraph that will be broken into several
lines.</SPAN> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>

the user agent could simulate start and end tags for span when inserting the fictional tag sequence for ::first-line to get the correct inheritance behavior.

<P><P::first-line><SPAN class="test"> This is a somewhat long HTML
paragraph that will </SPAN></P::first-line><SPAN class="test"> be broken into several
lines.</SPAN> The first line will be identified
by a fictional tag sequence. The other lines
will be treated as ordinary lines in the
paragraph.</P>

2.1.1. Finding the First Formatted Line

In CSS, the ::first-line pseudo-element can only have an effect when attached to a block container. The first formatted line of an element must occur inside a block-level descendant in the same flow (i.e., a block-level descendant that is not out-of-flow due to floating or positioning).

For example, the first line of the DIV in <DIV><P>This line...</P></DIV> is the first line of the P (assuming that both P and DIV are blocks).

The first line of a table-cell or inline-block cannot be the first formatted line of an ancestor element. Thus, in <DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P> etcetera</DIV> the first formatted line of the DIV is not the line "Hello".

Note: Note that the first line of the p in this fragment: <p><br>First... doesn’t contain any letters (assuming the default style for br). The word "First" is not on the first formatted line.

A user agent must act as if the fictional start tags of a ::first-line pseudo-element were nested just inside the innermost enclosing block-level element.

For example, the fictional tag sequence for
<DIV>
  <P>First paragraph</P>
  <P>Second paragraph</P>
</DIV>

is

<DIV>
  <P><DIV::first-line><P::first-line>First paragraph</P::first-line></DIV::first-line></P>
  <P><P::first-line>Second paragraph</P::first-line></P>
</DIV>

2.1.2. Styling the First Line Pseudo-element

The ::first-line pseudo-element’s generated box behaves similar to that of an inline-level element, but with certain restrictions. The following CSS properties apply to a ::first-line pseudo-element:

User agents may apply other properties as well.

2.1.3. Inheritance and the ::first-line Pseudo-element

During CSS inheritance, the portion of a child element that occurs on the first line only inherits properties applicable to the ::first-line pseudo-element from the ::first-line pseudo-element. For all other properties inheritence is from the non-pseudo-element parent of the first line pseudo element. (The portion of a child element that does not occur on the first line always inherits from the parent of that child.)

2.2. The ::first-letter pseudo-element

The ::first-letter pseudo-element represents the first typographic letter unit [CSS3TEXT] on the first formatted line of its originating element, if it is not preceded by any other content (such as images or inline tables) on its line. The ::first-letter pseudo-element can be used to create “initial caps” and “drop caps”, which are common typographic effects.

For example, the following rule creates a 2-line drop-letter on every paragraph following a level-2 header, using the initial-letter property defined in [CSS3LINE]:
h2 + p::first-letter { initial-letter: 2; }

Punctuation (i.e, characters that belong to the Punctuation (P*) Unicode general category [UAX44]) that precedes or follows the first typographic letter unit must also be included in the ::first-letter pseudo-element.

Quotes that precede the first letter should be included.

As explained in [CSS3TEXT], a typographic letter unit can include more than one Unicode codepoint. For example, combining characters must be kept with their base character. Also, languages may have additional rules about how to treat certain letter combinations. In Dutch, for example, if the letter combination "ij" appears at the beginning of an element, both letters should be considered within the ::first-letter pseudo-element. [UAX29] The UA should tailor its definition of typographic letter unit to reflect the first-letter traditions of the originating element’s content language.

This is actually a problem in cases where the originating element is an ancestor with a different content. What should we say here?

Note: Note that the first typographic letter unit may in fact be a digit, e.g., the “6” in “67 million dollars is a lot of money.”

If the characters that would form the ::first-letter are not in the same element, such as "‘T" in <p>'<em>T..., the user agent may create a ::first-letter pseudo-element from one of the elements, both elements, or simply not create a pseudo-element. Additionally, if the first letter(s) of the block are not at the start of the line (for example due to bidirectional reordering), then the user agent need not create the pseudo-element(s).

The ::first-letter pseudo-element is contained within any ::first-line pseudo-elements, and thus inherits from ::first-line.

2.2.1. Finding the First Letter

The first letter must occur on the first formatted line. For example, in this HTML fragment: <p><br>First... the first line doesn’t contain any letters and ::first-letter doesn’t match anything. In particular, it does not match the “F” of “First”.

In CSS, the ::first-letter pseudo-element only applies to block containers. A future version of this specification may allow this pseudo-element to apply to more display types. The ::first-letter pseudo-element can be used with all such elements that contain text, or that have a descendant in the same flow that contains text. A user agent should act as if the fictional start tag of the ::first-letter pseudo-element is just before the first text of the element, even if that first text is in a descendant.

Example: The fictional tag sequence for this HTML fragment:
<div>
<p>The first text.

is:

<div>
<p><div::first-letter><p::first-letter>T</...></...>he first text.

In CSS the first letter of a table-cell or inline-block cannot be the first letter of an ancestor element. Thus, in <DIV><P STYLE="display: inline-block">Hello<BR>Goodbye</P> etcetera</DIV> the first letter of the DIV is not the letter "H". In fact, the DIV doesn’t have a first letter. If an element is a list item (display: list-item), the ::first-letter applies to the first letter in the principal box after the marker. User-Agents may ignore ::first-letter on list items with list-style-position: inside. If an element has ::before or ::after content, the ::first-letter applies to the first letter of the element including that content.

Example: After the rule p::before {content: "Note: "}, the selector p::first-letter matches the "N" of "Note".

2.2.2. Styling the ::first-letter Pseudo-element

In CSS a ::first-letter pseudo-element is similar to an inline-level element if its float property is none; otherwise, it is similar to a floated element. The following properties that apply to ::first-letter pseudo-elements:

User agents may apply other properties as well.

Note: In previous levels of CSS, User Agents were allowed to choose a line height, width and height based on the shape of the letter, approximate font sizes, or to take the glyph outline into account when formatting. This possibility has been intentionally removed, as it proved to be a poor solution for the intended use case (Drop Caps), yet caused interoperability problems.

Example: This CSS and HTML example shows a possible rendering of an initial cap. Note that the fictional start tag of the first letter is inside the span, and thus the font weight of the first letter is normal, not bold as the span:
p { line-height: 1.1 }
p::first-letter { font-size: 3em; font-weight: normal }
span { font-weight: bold }
...
<p><span>Het hemelsche</span> gerecht heeft zich ten lange lesten<br>
Erbarremt over my en mijn benaeuwde vesten<br>
En arme burgery, en op mijn volcx gebed<br>
En dagelix geschrey de bange stad ontzet.
Image illustrating the ::first-letter pseudo-element
The following CSS will make a drop cap initial letter span about two lines:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML>
 <HEAD>
  <TITLE>Drop cap initial letter</TITLE>
  <STYLE type="text/css">
   P               { font-size: 12pt; line-height: 1.2 }
   P::first-letter { font-size: 200%; font-weight: bold; float: left }
   SPAN            { text-transform: uppercase }
  </STYLE>
 </HEAD>
 <BODY>
  <P><SPAN>The first</SPAN> few words of an article
    in The Economist.</P>
 </BODY>
</HTML>

This example might be formatted as follows:

Image illustrating the combined effect of the ::first-letter
   and ::first-line pseudo-elements

The fictional tag sequence is:

<P>
  <SPAN>
    <P::first-letter>
      T
    </P::first-letter>he first
  </SPAN>
  few words of an article in the Economist.
</P>

Note that the ::first-letter pseudo-element tags abut the content (i.e., the initial character), while the ::first-line pseudo-element start tag is inserted right after the start tag of the block element.

3. Highlight Range Pseudo-element: ::selection

The ::selection pseudo-element represents the portion of a document that has been highlighted by the user. This also applies, for example, to selected text within an editable text field.

We want to add other types of selections, such as spelling-error highlights.

Active vs. inactive selections are often styled differently. Currently no way to distinguish.

The root highlight is a multi-piece overlay over the entire tree, portions of which are selected and correspond to the ::selection pseudo-element. Each box owns the piece of of the overlay corresponding to any text or replaced content directly contained by the box. For text, the corresponding overlay must cover at least the entire em box and may extend further above/below the em box to the line box edges. Spacing between two characters may also be part of the overlay, in which case it belongs to the innermost element that contains both characters and is selected when both characters are selected For replaced content, the associated overlay must cover at least the entire replaced object, and may extend outward to include the element’s entire content box. The overlay may also include other other areas within the border-box of an element; in this case, those areas belong to the innermost such element that contains the area.

See F2F minutes, dbaron’s message, Daniel’s thread, Gecko notes, Opera notes, Webkit notes

Each element draws its own portion of the highlighted overlay, which receives the styles specified by the ::selection pseudo-element styles for which it or one of its ancestors is the originating element. When multiple styles conflict, the winning style is the one belonging to the innermost element after cascading.

This could alternately be described in terms of inheritance. So, how do we want inherit to behave here? Should it inherit from the parent ::selection or the originating element? Opera does the former, Gecko/Blink the latter.

Authors wanting multiple selections styles should use :root::selection for their document-wide selection style, since this will allow clean overriding in descendants. (::selection alone would apply to every element in the tree, overriding the more specific styles of any ancestors.)

3.1. Styling Highlighted Ranges

The following properties apply to ::selection pseudo-elements:

Are there any other properties that should be included here? [Caret-color should be added once we have it.]

Note: Historically (and at the time of writing) only color and background-color have been interoperably supported.

If color is not specified, the text (and text decoration)'s unselected color must be used for the highlight. (As usual, the initial background-color is transparent.)

Can we reuse currentColor for this, now that it computes to itself?

The UA should use the OS-default selection color when neither color nor background-color has been specified by the author.

Note: This paired-cascading behavior does not allow using the normal cascade to represent the OS default selection colors. However it has been interoperably implemented in browsers and is thus probably a Web-compatibility requirement.

The ::selection pseudo element draws its background over the selected portion of the element, immediately below any positioned descendants (i.e. just before step 8 in CSS2.1§E.2). It also suppresses the drawing of any selected text and instead redraws that text (and any text decorations) over that background using the specified color.

Implementations seem to redraw text decorations and text shadows over the selection background. This seems particularly weird if the text decoration color doesn’t match the text. Perhaps the only thing visible should be the text itself (unless the background is transparent) and any text decorations specified for the selection itself. (Alternately the decorations should get the color of the selected text, not the unselected text.)

For non-replaced content, the UA must honor the color and background-color (including their alpha channels) as specified. However, for replaced content, the UA should create a semi-transparent wash to coat the content so that it can show through the selection. This wash should be of the specified background-color if that is not transparent, else the specified color; however the UA may adjust the alpha channel if it is opaque.

This whole section needs vocabulary cleanup.

4. Generated Content Pseudo-elements: ::before and ::after

When their computed content value is not none, these pseudo-elements generate boxes as if they were immediate children of their originating element, and can be styled exactly like any normal document-sourced element in the document tree. They inherit any inheritable properties from their originating element; non-inheritable properties take their initial values as usual. [CSS3CASCADE]

::before
Represents a styleable child pseudo-element immediately before the originating element’s actual content.
::after
Represents a styleable child pseudo-element immediately before the originating element’s actual content.
For example, the following rule inserts the string “Note: ” before the content of every <p> element whose class attribute has the value note:
p.note::before { content: "Note: " }

Since the initial value of display is inline, this will generate an inline box. Like other inline children of <p>, it will participate in <p>’s inline formatting context, potentially sharing a line with other content.

As with the content of regular elements, the generated content of ::before and :after pseudo-elements may be included in any ::first-line and ::first-letter pseudo-elements applied to its originating element.

For compatibility with existing style sheets written against CSS Level 2 [CSS21], user agents must also accept the previous one-colon notation (:before and :after) for these pseudo-elements.

4.1. Alternative text for Generated Content: The alt property

The generated content of a ::before or ::after element is not always appropriate for assistive technology. In these cases, alternative text can be provided using the alt property. The alt property applies only to the same elements the content property applies to.

Name:alt
Value:none | <string>
Initial:none
Applies to:::before and ::after pseudo-elements
Inherited:no
Percentages:n/a
Media:visual
Computed value:as specified
Animatable:no
none
No alternative text
<string>
The alternative text is the <string>. This can be the empty string.

When the alt property computes to anything other than none, the alternative <string> should be used instead of the value of the contents property by assistive technology.

Here the content property is an image, so the alt property is required to provide alternative text.

.new::before { 
  content: url(./img/star.png);
  alt: "New!"; 
}

If the pseudo-element is purely decorative and its function is covered elsewhere, setting alt to the empty string can avoid reading out the decorative element. Here the ARIA attribute will be spoken as "collapsed". Without the empty string alt value, the content would also be spoken as "Black right-pointing pointer".

.expandable::before {
  content: "\25BA"; /* a.k.a. ► */
  alt: ""; 
  /* aria-expanded="false" already in DOM, 
     so this pseudo-element is decorative */
}

5. Overlapping Pseudo-element Interactions

Recall that

The following CSS and HTML example illustrates how overlapping pseudo-elements interact:

p { color: red; font-size: 12pt }
p::first-letter { color: green; font-size: 200% }
p::first-line { color: blue }
      
<P>Some text that ends up on two lines</P>

The first letter of each P element will be green with a font size of ’24pt'. The rest of the first formatted line will be blue while the rest of the paragraph will be red.

Assuming that a line break will occur before the word "ends", the fictional tag sequence for this fragment might be:

<P>
<P::first-line>
<P::first-letter>
S
</P::first-letter>ome text that
</P::first-line>
ends up on two lines
</P>

6. Additions to the CSS Object Model

Pseudo-elements should be reachable by script, stylable from script, and available as event targets.

Note We may extend this section in the future to allow creation of pseudo-elements from script.

6.1. Interface CSSPseudoElement

The CSSPseudoElement interface allows pseudo-elements to be styleable from script and makes them event targets.

The approach in this draft is to start with a bare minimum for the CSSPseudoElement interface and build up from there. Another more radical approach could take everything that’s common between a pseudo-element and a node and create a new base class for both Node and CSSPseudoElement.
interface CSSPseudoElement {
    readonly attribute DOMString type;
    readonly attribute CSSStyleDeclaration style;
};

CSSPseudoElement implements EventTarget;

The type attribute is a string representing the type of the pseudo-element. This can be one of the following values:

‘before’
The pseudo-element was created before the element’s contents.
‘after’
The pseudo-element was created after the element’s contents.
‘letter’
The pseudo-element is the first letter of the element.
‘line’
The pseudo-element is the first line of the element.
‘selection’
The selection pseudo-element for the element.

The style attribute is a CSSStyleDeclaration [CSSOM] that allows directly setting style information (inline styles) onto the pseudo-element. Inline styles on a CSSPseudoElement have precedence over all style rules styling that pseudo-element.

This should cascade like actual inline styles, not be a different thing.

The EventTarget interface [DOM-LEVEL-2-EVENTS] must be implemented by all instances of CSSPseudoElement as a conformance requirement of this module.

6.2. Interface CSSPseudoElementList

The CSSPseudoElementList represents an ordered collection of CSSPseudoElement instances.

interface CSSPseudoElementList {
    readonly attribute unsigned long length;
    CSSPseudoElement item(unsigned long index);
    CSSPseudoElement getByType(DOMString type);
                     // replies null if no pseudo-element exists for
                     //     the requested type
};

The length attribute represents the number of CSSPseudoElement in the collection or zero if it is empty. The method item() is used to retrieve a CSSPseudoElement by index. It takes one parameter being the requested index into the collection. Its return value is the CSSPseudoElement at the requested index in the collection or null if that is not a valid index.

The method getByType() is used to retrieve a CSSPseudoElement by its type. Its return value is the CSSPseudoElement in the collection that matches the type or null if there is no CSSPseudoElement in the collection for that type.

6.3. Addition to the window interface

A new method is added to the Window interface to retrieve pseudo-elements created by a given element for a given type:

partial interface Window {
  CSSPseudoElementList getPseudoElements(Element elt,
                                       DOMString type);
};

The getPseudoElements() method is used to retrieve all CSSPseudoElement instances created by the element elt for the type type. Its return value is a CSSPseudoElementList, potentially empty if no pseudo-element exists for the given element and the given type.

Acknowledgements

The editors would like to thank the following individuals for their contributions, either during the conception of the specification or during its development and specification review process: Tab Atkins, David Baron, Razvan Caliman, Chris Coyier, Anders Grimsrud, Vincent Hardy.

Conformance

Document conventions

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.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word "Note" and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

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.

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.)

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.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not 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.

Experimental implementations

To avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.

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.

Non-experimental implementations

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.

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.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

References

Normative References

[CSS3TEXT]
Elika J. Etemad; Koji Ishii. CSS Text Module Level 3. 13 November 2012. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2012/WD-css3-text-20121113/
[DOM-Level-2-Events]
Tom Pixley. Document Object Model (DOM) Level 2 Events Specification. 13 November 2000. REC. URL: http://www.w3.org/TR/DOM-Level-2-Events/
[UAX44]
Mark Davis; Ken Whistler. Unicode Character Database. 25 September 2013. URL: http://www.unicode.org/reports/tr44/
[cssom]
Simon Pieters; Glenn Adams. CSS Object Model (CSSOM). 5 December 2013. WD. URL: http://www.w3.org/TR/cssom/
[rfc2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: http://www.ietf.org/rfc/rfc2119.txt
[selectors4]
Elika Etemad; Tab Atkins Jr.. Selectors Level 4. 2 May 2013. WD. URL: http://www.w3.org/TR/selectors4/

Informative References

[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-CSS2-20110607
[CSS3-TEXT-DECOR]
Elika J. Etemad; Koji Ishii. CSS Text Decoration Module Level 3. 1 August 2013. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2013/CR-css-text-decor-3-20130801/
[CSS3BG]
Bert Bos; Elika J. Etemad; Brad Kemper. CSS Backgrounds and Borders Module Level 3. 24 July 2012. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2012/CR-css3-background-20120724/
[CSS3CASCADE]
Håkon Wium Lie; Elika J. Etemad; Tab Atkins Jr.. CSS Cascading and Inheritance Level 3. 3 October 2013. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2013/CR-css-cascade-3-20131003/
[CSS3COLOR]
Tantek Çelik; Chris Lilley; L. David Baron. CSS Color Module Level 3. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-css3-color-20110607
[CSS3LINE]
Michel Suignard; Eric A. Meyer. CSS3 module: line. 15 May 2002. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2002/WD-css3-linebox-20020515
[UAX29]
Mark Davis. Text Boundaries. 25 March 2005. Unicode Standard Annex #29. URL: http://www.unicode.org/unicode/reports/tr29/tr29-9.html
[css3-fonts]
John Daggett. CSS Fonts Module Level 3. 11 December 2012. WD. URL: http://www.w3.org/TR/css3-fonts/
[html5]
Robin Berjon; et al. HTML5. 16 September 2014. PR. URL: http://www.w3.org/TR/html5/

Index

Property Index

NameValueInitialApplies toInh.%agesMediaAnimatableComputed value
altnone | <string>none::before and ::after pseudo-elementsnon/avisualnoas specified

IDL Index

interface CSSPseudoElement {
    readonly attribute DOMString type;
    readonly attribute CSSStyleDeclaration style;
};

CSSPseudoElement implements EventTarget;

interface CSSPseudoElementList {
    readonly attribute unsigned long length;
    CSSPseudoElement item(unsigned long index);
    CSSPseudoElement getByType(DOMString type);
                     // replies null if no pseudo-element exists for
                     //     the requested type
};

partial interface Window {
  CSSPseudoElementList getPseudoElements(Element elt,
                                       DOMString type);
};

Issues Index

This is actually a problem in cases where the originating element is an ancestor with a different content. What should we say here?
We want to add other types of selections, such as spelling-error highlights.
Active vs. inactive selections are often styled differently. Currently no way to distinguish.
See F2F minutes, dbaron’s message, Daniel’s thread, Gecko notes, Opera notes, Webkit notes
This could alternately be described in terms of inheritance. So, how do we want inherit to behave here? Should it inherit from the parent ::selection or the originating element? Opera does the former, Gecko/Blink the latter.
Are there any other properties that should be included here? [Caret-color should be added once we have it.]
Can we reuse currentColor for this, now that it computes to itself?
Implementations seem to redraw text decorations and text shadows over the selection background. This seems particularly weird if the text decoration color doesn’t match the text. Perhaps the only thing visible should be the text itself (unless the background is transparent) and any text decorations specified for the selection itself. (Alternately the decorations should get the color of the selected text, not the unselected text.)
This whole section needs vocabulary cleanup.
The approach in this draft is to start with a bare minimum for the CSSPseudoElement interface and build up from there. Another more radical approach could take everything that’s common between a pseudo-element and a node and create a new base class for both Node and CSSPseudoElement.
This should cascade like actual inline styles, not be a different thing.