<pre class='metadata'>
Title: CSS Pseudo-Elements Module Level 4
Shortname: css-pseudo
Level: 4
Status: ED
Work Status: Refining
Group: csswg
ED: https://drafts.csswg.org/css-pseudo-4/
TR: https://www.w3.org/TR/css-pseudo-4/
Previous Version: https://www.w3.org/TR/2020/WD-css-pseudo-4-20201231/
Previous Version: https://www.w3.org/TR/2019/WD-css-pseudo-4-20190225/
Previous Version: https://www.w3.org/TR/2016/WD-css-pseudo-4-20160607/
Previous Version: https://www.w3.org/TR/2015/WD-css-pseudo-4-20150115/
!Issues List: <a href="https://drafts.csswg.org/css-pseudo/#issues-index">Tracked in Editor's Draft</a>
Former Editor: Daniel Glazman, Disruptive Innovations, w3cid 13329
Editor: Elika J. Etemad / fantasai, Apple, http://fantasai.inkedblade.net/contact, w3cid 35400
Editor: Alan Stearns, Adobe Systems Inc., stearns@adobe.com, w3cid 46659
Abstract: This CSS module defines pseudo-elements, abstract elements that represent portions of the CSS render tree that can be selected and styled.
At Risk: the ''::prefix'' and ''::suffix'' sub-elements of ''::first-letter''
Ignored Terms: initial-letter, PseudoElement, pseudo(), selectors
Default Highlight: css
Indent: 2
WPT Path Prefix: css/css-pseudo/
WPT Display: closed
</pre>
<pre class="link-defaults">
spec:css-color-4; type:value; text:currentcolor
spec:css-color-4; type:property; text:color
spec:fill-stroke-3; type:property; text:stroke-width
spec:css-lists-3; type:dfn; text:marker
spec:css-backgrounds-3; type:property; text:box-shadow
</pre>

<h2 id="intro">Introduction</h2>

  <em>This section is informative.</em>

  <a>Pseudo-elements</a> 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,
  they can be used to 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
  <em>after</em> text wrapping,
  allowing just that line to be styled differently
  from the rest of the paragraph.

  Each pseudo-element is associated with an <a>originating element</a>
  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 <a>selectors</a>,
  see [[!SELECTORS-4]].

  Note: As a reminder,
  pseudo-elements cannot be chained together unless explicitly allowed.
  For example, ''::marker::before'' is not allowed;
  but ''::before::marker'' is.

  Note: Level 4 is the first version of the CSS Pseudo specification
  under this name.
  It was branched from the Selectors 3 [[SELECTORS-3]] specification,
  and thus started at level 4,
  with the remainder of Selectors 3 becoming Selectors 4 [[SELECTORS-4]].


<h2 id="typographic-pseudos">
Typographic Pseudo-elements</h2>

<h3 id="first-line-pseudo">
First-Line Text: the ''::first-line'' pseudo-element</h3>

  The <dfn>::first-line</dfn> [=pseudo-element=] represents
  the contents of the [=first formatted line=]
  of its [=originating element=].

  <wpt>
    crashtests/first-line-marquee-crash.html
    first-line-allowed-properties.html
    first-line-and-marker.html
    first-line-and-placeholder.html
    first-line-change-inline-color-nested.html
    first-line-change-inline-color.html
    first-line-first-letter-insert-crash.html
    first-line-float-mapped-attribute-crash.html
    first-line-inherited-no-transition.html
    first-line-inherited-transition-crash.html
    first-line-inherited-with-transition.html
    first-line-input-image-crash.html
    first-line-line-height-001.html
    first-line-line-height-002.html
    first-line-nested-gcs.html
    first-line-on-ancestor-block.html
    first-line-opacity-001-ref.html
    first-line-opacity-001.html
    first-line-replaced-001.html
    first-line-with-before-after.html
    first-line-with-inline-block-before.html
    first-line-with-inline-block.html
    first-line-with-out-of-flow-and-nested-div.html
    first-line-with-out-of-flow-and-nested-span.html
    first-line-with-out-of-flow.html
  </wpt>

  <div class="example">
    The rule below means
    “change the letters of the first line of every <code>p</code> element to uppercase”:

    <pre class="lang-css">p::first-line { text-transform: uppercase }</pre>

    The selector ''p::first-line''
    does not match any real document element.
    It instead matches a pseudo-element
    that the user agent will automatically insert
    at the beginning of every <code>p</code> element.
  </div>

  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.

  <div class="example" id="first-line-example">
    For example, given an ordinary HTML [[HTML5]] paragraph such as:

    <pre class="lang-markup">
      &lt;P&gt;This is a somewhat long HTML paragraph
      that will be broken into several lines.
      The first line will be styled
      by the ‘::first-line’ pseudo-element.
      The other lines will be treated
      as ordinary lines in the paragraph.&lt;/P&gt;
    </pre>

    Depending on the width of the element,
    its lines might be broken as follows:

    <pre class="figure">
      THIS IS A SOMEWHAT LONG HTML PARAGRAPH THAT
      will be broken into several lines. The first
      line will be styled by the ‘::first-line’
      pseudo-element. The other lines will be
      treated as ordinary lines in the paragraph.
    </pre>

    or alternately as follows:

    <pre class="figure">
      THIS IS A SOMEWHAT LONG
      HTML paragraph that will
      be broken into several
      lines. The first line will
      be styled by the
      ‘::first-line’ pseudo-
      element. The other lines
      will be treated as ordinary
      lines in the paragraph.
    </pre>
  </div>

<h4 id="first-text-line">
Finding the First Formatted Line</h4>

  In CSS, the ''::first-line'' [=pseudo-element=]
  can only have an effect when attached to a <a>block container</a>:

  * The <dfn export>first formatted line</dfn> of
    a [=block container=] that establishes an [=inline formatting context=]
    represents the [=inline-level=] content of its first [=line box=].
  * The [=first formatted line=] of
    a [=block container=] or [=multi-column container=]
    that contains [=block-level=] content
    (and is not a [=table wrapper box=])
    is the [=first formatted line=] of
    its first [=in-flow=] [=block-level=] child.
    If no such line exists,
    it has no [=first formatted line=].

  Note: The [=first formatted line=] can be an empty line.
  For example, the first line of the <code>p</code> in
  <code class="lang-markup">&lt;p&gt;&lt;br&gt;First&hellip;</code>
  doesn't contain any letters.
  Thus the word “First” is not on the first formatted line,
  and will not be affected by ''p::first-line''.

  Note: The first line of a [=block container=]
  that does not itself participate in a [=block formatting context=]
  cannot be the first formatted line of an ancestor element.
  Thus, in <code class="lang-markup">&lt;DIV&gt;&lt;P STYLE="display: inline-block"&gt;Hello&lt;BR&gt;Goodbye&lt;/P&gt; etcetera&lt;/DIV&gt;</code>
  the first formatted line of the <code>DIV</code> is not the line “Hello”,
  but rather the line that contains that entire inline block.

  When a [=first formatted line=] is represented
  by multiple ''::first-line'' pseudo-elements,
  they are nested in the same order as their [=originating elements=].
  The [=inline-level=] contents of this line--
  including its [=root inline box=] fragment--
  are nested within the innermost ''::first-line'' [=pseudo-element=].

  <wpt>
    first-line-below-float.html
    first-line-on-list-item-with-block-children.html
  </wpt>

  <div class="example">
    Consider the following markup:
    <pre class="lang-markup">
      &lt;DIV&gt;
        &lt;P&gt;First paragraph&lt;/P&gt;
        &lt;P&gt;Second paragraph&lt;/P&gt;
      &lt;/DIV&gt;
    </pre>

    If we assume a [=fictional tag sequence=] to represent
    the elements’ ''::first-line'' pseudo-elements,
    it would be something like:

    <pre class="lang-markup">
      &lt;DIV&gt;
        &lt;P&gt;&lt;DIV::first-line&gt;&lt;P::first-line&gt;First paragraph&lt;/P::first-line&gt;&lt;/DIV::first-line&gt;&lt;/P&gt;
        &lt;P&gt;&lt;P::first-line&gt;Second paragraph&lt;/P::first-line&gt;&lt;/P&gt;
      &lt;/DIV&gt;
    </pre>
  </div>

<h4 id="first-line-styling">
Styling the ''::first-line'' Pseudo-element</h4>

  The ''::first-line'' pseudo-element’s generated box
  behaves similar to that of an [=inline-level box=], but with certain restrictions.
  The following CSS properties apply to a ''::first-line'' [=pseudo-element=]:
  <ul>
    <li>all font properties (see [[CSS-FONTS-4]])
    <li>the 'color' and 'opacity' properties (see [[CSS-COLOR-4]])
    <li>all background properties (see [[CSS-BACKGROUNDS-3]])
    <li>any typesetting properties that apply to inline elements (see [[CSS-TEXT-4]])
    <li>all text decoration properties (see [[CSS-TEXT-DECOR-4]])
    <li>the 'ruby-position' property (see [[CSS-RUBY-1]])
    <li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
    <li>any other properties defined to apply to ''::first-line''
        by their respective specifications
  </ul>

  User agents may apply other properties as well except for
  the following excluded properties:
  <ul>
    <li>'writing-mode'
    <li>'direction'
    <li>'text-orientation'
  </ul>

  Note: Setting 'line-height' on ''::first-line'' inherits to
  the fragment of the [=root inline box=]
  that wraps the contents of the first line,
  and therefore can both increase and decrease the height of the first line box.

  <wpt>
    first-line-line-height-003.html
  </wpt>

<h4 id="first-line-inheritance">
Inheritance and the ''::first-line'' Pseudo-element</h4>

  During CSS [=inheritance=],
  the [=box fragment|fragment=] of a child that occurs on the first line
  inherits any standard [=inherited properties=]--
  except the properties excluded above--
  from the ''::first-line'' [=pseudo-element=].
  For all other properties,
  including all [=custom properties=] [[!CSS-VARIABLES-1]],
  inheritance is
  from the non-pseudo parent.
  (The portion of a child element that does not occur on the first line
  always inherits from the non-pseudo parent.)


  <div class="example">
    In the common case (of standard inherited CSS properties),
    [=inheritance=] into and from a ''::first-line'' pseudo-element
    can be understood by writing out a <dfn>fictional tag sequence</dfn>
    to represent ''::first-line''.
    Consider the <a href="#first-line-example">earlier example</a>;
    in case of the first rendering, the fictional tag sequence would be:

    <pre class="lang-markup">
      &lt;P&gt;<strong>&lt;p::first-line></strong>This is a somewhat long HTML paragraph
      that<strong>&lt;/p::first-line></strong> will be broken into several lines.
      The first line will be styled
      by the ‘::first-line’ pseudo-element.
      The other lines will be treated
      as ordinary lines in the paragraph.&lt;/p&gt;
    </pre>

    And in the case of the second rendering:

    <pre class="lang-markup">
      &lt;p&gt;<strong>&lt;p::first-line></strong>This is a somewhat long<strong>&lt;/p::first-line></strong> HTML paragraph
      that will be broken into several lines.
      The first line will be styled
      by the ‘::first-line’ pseudo-element.
      The other lines will be treated
      as ordinary lines in the paragraph.&lt;/p&gt;
    </pre>
  </div>


  <div class="example">
    If a pseudo-element breaks up a real element,
    the effect can often be described
    by a <a>fictional tag sequence</a>
    that closes and then re-opens the element.
    Suppose we mark up the earlier example
    with a <code>span</code> element encompassing the first sentence:

    <pre class="lang-markup">
      &lt;p&gt;<strong>&lt;span></strong>This is a somewhat long HTML paragraph
      that will be broken into several lines.<strong>&lt;/span></strong>
      The first line will be styled
      by the ‘::first-line’ pseudo-element.
      The other lines will be treated
      as ordinary lines in the paragraph.&lt;/p&gt;
    </pre>

    The effect of the first rendering
    would be similar to the following [=fictional tag sequence=]:

    <pre class="lang-markup">
      &lt;p&gt;<strong>&lt;p::first-line>&lt;span></strong>This is a somewhat long HTML paragraph
      that<strong>&lt;/span>&lt;/p::first-line>&lt;span></strong> will be broken into several lines.<strong>&lt;/span></strong>
      The first line will be styled
      by the ‘::first-line’ pseudo-element.
      The other lines will be treated
      as ordinary lines in the paragraph.&lt;/p&gt;
    </pre>
  </div>


<h3 id="first-letter-pseudo">
First-Letter Text: ''::first-letter'' pseudo-element and its ''::prefix'' and ''::suffix'' children</h3>

  <wpt>
    first-letter-001.html
    first-letter-002.html
    first-letter-003.html
    first-letter-004.html
    first-letter-005.html
    first-letter-allowed-properties.html
    first-letter-and-sibling-display-change.html
    first-letter-and-whitespace.html
    first-letter-background-image-dynamic.html
    first-letter-background-image.html
    first-letter-bidi-pre-crash.html
    first-letter-block-to-inline.html
    first-letter-crash.html
    first-letter-digraph.html
    first-letter-exclude-block-child-marker.html
    first-letter-exclude-inline-child-marker.html
    first-letter-exclude-inline-marker.html
    first-letter-first-line-dynamic-001-crash.html
    first-letter-hi-001.html
    first-letter-hi-002.html
    first-letter-list-item-dynamic-001.html
    first-letter-of-html-root-refcrash.html
    first-letter-opacity-001-ref.html
    first-letter-opacity-001.html
    first-letter-opacity-float-001.html
    first-letter-punctuation-and-space.html
    first-letter-punctuation-dynamic.html
    first-letter-skip-empty-span-nested.html
    first-letter-skip-empty-span.html
    first-letter-skip-marker.html
    first-letter-text-and-display-change.html
    first-letter-width-2.html
    first-letter-width.html
    first-letter-with-before-after.html
    first-letter-with-preceding-new-line.html
    first-letter-with-quote.html
    first-letter-with-span.html
  </wpt>

  <div class="figure">
    <img src="images/first-letter2.gif" width="114" height="72"
         alt="A drop-cap initial letter, including the opening quotation mark before it.">
  </div>

  The <dfn>::first-letter</dfn> [=pseudo-element=] represents
  the first Letter, Number, or Symbol
  (Unicode category <code>L*</code>, <code>N*</code>, or <code>S*</code>) [=typographic character unit=]
  on the <a>first formatted line</a> of its <a>originating element</a>
  (the <dfn>first letter</dfn>)
  as well as its associated punctuation.
  Collectively, this text is the <dfn>first-letter text</dfn>.
  The ''::first-letter'' pseudo-element can be used
  to create “initial caps” and “drop caps”,
  which are common typographic effects.

  <div class="example">
    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 [[CSS-INLINE-3]]:

    <pre class="lang-css">h2 + p::first-letter { initial-letter: 3; }</pre>
  </div>

  Note: The [=first letter=] may in fact be a digit,
  e.g., the “6” in “67 million dollars is a lot of money.”

  To allow independent styling of the [=first letter=] itself
  and its adjacent punctuation,
  associated preceding punctuation
  is represented by the <dfn for="::first-letter">::prefix</dfn>
  [=sub-pseudo-element=] of the ''::first-letter'' [=pseudo-element=]
  (''::first-letter::prefix'');
  and associated following punctuation
  is represented by the <dfn for="::first-letter">::suffix</dfn>
  [=sub-pseudo-element=] of the ''::first-letter'' [=pseudo-element=]
  (''::first-letter::suffix'').
  See [[#first-letter-pattern]], below.

<h4 id="first-letter-pattern">
First Letters and Associated Punctuation</h4>

  As explained in [[CSS-TEXT-3#characters]],
  a <a>typographic character unit</a> 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]]
  When selecting the [=first letter=],
  the UA should tailor its definition of <a>typographic character unit</a>
  to reflect the first-letter traditions of
  the ''::first-letter'' pseudo-element’s <em>[=containing block=]</em>’s [=content language=].

  Preceding and following punctuation
  must also be included as part of the [=first-letter text=]
  in the ''::first-letter'' pseudo-element
  as follows:
  <ul>
    <li>
      All punctuation--
      i.e, characters that belong to the Punctuation (<code>P*</code>) <a>Unicode general category</a> [[!UAX44]]--
      that precedes the [=first letter=],
      as well as any intervening typographic space--
      characters belonging to the <code>Zs</code> Unicode general category [[!UAX44]]
      <em>other than</em>
      U+3000 IDEOGRAPHIC SPACE.
    <li>
      Any punctuation other than opening punctuation and dashes--
      i.e. characters that belong to the Punctuation (<code>P*</code>) <a>Unicode general category</a>,
      excluding Open Punctuation (<code>Ps</code>)
      and Dash Punctuation (<code>Pd</code>)--
      that follows the [=first letter=],
      as well as any intervening typographic space--
      characters belonging to the <code>Zs</code> Unicode general category [[!UAX44]]
      <em>other than</em>
      U+3000 IDEOGRAPHIC SPACE or a [=word separator=].
  </ul>

  <div class="note">
    Informally, the [=first-letter text=]’s pattern here
    can be roughly
    (ignoring the exclusions from <code>Zs</code>)
    represented as a “regular expression”
    <code highlight="bnf" style="font-family: inherit">
    (P (Zs|P)*)? (L&#x7c;N|S) ((Zs|P−(Ps|Pd))* (P−(Ps|Pd))?</code>--
    or, alternatively,
    <code highlight="bnf" style="font-family: inherit">
    (&#91;P] [Zs P]*)? [L N S] ([Zs [P--[Ps Pd]]]* [P--[Ps Pd]])?</code>--
    where the Unicode category abbreviation represents the set
    of all [=typographic character units=] belonging to that category.

    <!-- this is not actually BNF, but it highlights better that way -->

    <!-- Bikeshed is <a href="https://github.com/tabatkins/bikeshed/issues/2202">eating punctuation</a> in this note (unless escaped with undocumented escape sequences), which is not helpful. -->

    <pre class=railroad>
      Optional:
        Sequence:
          N: P
          ZeroOrMore:
            Choice:
              N: P
              N: Zs
      Choice:
        N: L
        N: N
        N: S
      Optional:
        Sequence:
          N: P − (Ps ∪ Pd)
          ZeroOrMore:
            Choice:
              N: P − (Ps ∪ Pd)
              N: Zs
    </pre>
  </div>

  See [[css-text-3#characters]] and [[css-text-3#character-properties]]
  for more information on [=typographic character units=]
  and their Unicode properties.
  [[!CSS-TEXT-3]]

<h4 id="first-letter-application">
Finding the First-Letter Text</h4>

  As with ''::first-line'',
  the ''::first-letter'' [=pseudo-element=]
  can only have an effect when attached to a [=block container=].
  Its [=first-letter text=] is the first such [=inline-level content=]
  participating in the [=inline formatting context=]
  of its [=originating element=]’s [=first formatted line=],
  if it is not preceded by any other [=in-flow=] content
  (such as images or inline tables) on its line.

  For this purpose, any [=marker boxes=] are ignored,
  as if they were [=out-of-flow=].
  However, if an element has [=in-flow=] ''::before'' or ''::after'' content,
  the [=first-letter text=] is selected from the content of the element
  <em>including</em> that generated content.

  <div class="example">
    Example:
    After the rule <code class="lang-css">p::before {content: "Note: "}</code>, the
    selector ''p::first-letter'' matches the "N" of "Note".
  </div>

  If no qualifying text exists,
  then there is no [=first-letter text=]
  and no ''::first-letter'' pseudo-element.

  Note: When the [=first formatted line=] is empty,
  ''::first-letter'' will not match anything.
  For example, in this HTML fragment:
  <code class="lang-markup">&lt;p&gt;&lt;br&gt;First...</code>
  the first line doesn't contain any letters,
  so ''::first-letter'' doesn't match anything.
  In particular, it does not match the “F” of “First”,
  which is on the second line.

  Note: As with ''::first-line'',
  the [=first-letter text=] of a [=block container=]
  that does not participate in a [=block formatting context=]
  cannot be the [=first-letter text=] of an ancestor element.
  Thus, in <code class="lang-markup">&lt;DIV&gt;&lt;P STYLE="display: inline-block"&gt;Hello&lt;BR&gt;Goodbye&lt;/P&gt; etcetera&lt;/DIV&gt;</code>
  the [=first letter=] of the <code>DIV</code> is not the letter “H”.
  In fact, the <code>DIV</code> doesn't have a [=first letter=].

  Any portion of the [=first-letter text=]
  that is wrapped to the next line
  no longer forms part of the ''::first-letter'' [=pseudo-element=].

<h4 id="first-letter-tree">
Inheritance and Box Tree Structure of the First-Letter Pseudo-elements</h4>

  The ''::first-letter'' [=pseudo-element=] is wrapped
  immediately around the [=first-letter text=] it represents,
  even if that text is in a descendant.
  When a [=first-letter text=] is represented by multiple ''::first-letter'' pseudo-elements,
  they are nested in the same order as their [=originating elements=].
  [=Inheritance=] behaves accordingly.

  <div class="example">
    Consider the following markup:

    <pre class="lang-markup">
      &lt;div&gt;
        &lt;p&gt;&lt;span&gt;The first few words&lt;/span>
        and the rest of the paragraph.
      &lt;/div&gt;
    </pre>

    If we assume a [=fictional tag sequence=]
    to represent the elements’ ''::first-letter'' pseudo-elements,
    it would be something like:

    <pre>
      &lt;div&gt;
        &lt;p&gt;&lt;span&gt;<strong>&lt;div::first-letter&gt;&lt;p::first-letter&gt;</strong>T<strong>&lt;/&hellip;&gt;&lt;/&hellip;&gt;</strong>he first few words&lt;/span>
        and the rest of the paragraph.
      &lt;/div&gt;
    </pre>
  </div>

  If any ''::first-letter::prefix'' or ''::first-letter::suffix'' [=pseudo-elements=] exist,
  they are nested within the innermost ''::first-letter'',
  and otherwise interpreted similar to ''::first-letter'' itself.

  <div class="example">
    Consider the following markup:

    <pre class="lang-markup">
      &lt;div&gt;
        &lt;p&gt;&lt;span&gt;“The first few words&lt;/span>
        and the rest of the quotation.
      &lt;/div&gt;
    </pre>

    If we assume a [=fictional tag sequence=]
    to represent the elements’ ''::first-letter'' pseudo-elements,
    it would be something like:

    <pre>
      &lt;div&gt;
        &lt;p&gt;&lt;span&gt;&lt;div::first-letter&gt;&lt;p::first-letter&gt;<strong>&lt;div::first-letter::prefix&gt;&lt;p::first-letter::prefix&gt;</strong>“<strong>&lt;/&hellip;&gt;&lt;/&hellip;&gt;</strong>T&lt;/&hellip;&gt;&lt;/&hellip;&gt;he first few words&lt;/span>
        and the rest of the paragraph.
      &lt;/div&gt;
    </pre>
  </div>

  If the characters that would form the [=first-letter text=]
  are not all in the same element
  (as the <code>‘T</code> in <code class="lang-css">&lt;p&gt;‘&lt;em&gt;T...</code>),
  the user agent may create the ''::first-letter'' [=pseudo-element=]
  (and its ''::prefix'' or ''::suffix'' sub-elements, if any)
  from one of the elements, or all elements,
  or simply not create the pseudo-element(s).
  Additionally, if the [=first-letter text=]
  is not at the start of the line
  (for example due to bidirectional reordering,
  or due to a [=list item=] [=marker=] with ''list-style-position: inside''),
  then the user agent is not required to create the pseudo-element(s).

  A ''::first-letter'' pseudo-element is contained within
  any ''::first-line'' pseudo-elements,
  and thus inherits (potentially indirectly) from ''::first-line'',
  the same as any [=inline box=] on the same line.

<h4 id="first-letter-styling">
Styling the First-Letter Pseudo-elements</h4>

  In CSS a ''::first-letter'' [=pseudo-element=]
  (and its ''::prefix'' and ''::suffix'' sub-elements)
  is similar to an [=inline box=].
  The following properties apply to
  ''::first-letter'', ''::first-letter::prefix'', and ''::first-letter::suffix''
  pseudo-elements:

  <ul>
    <li>all font properties (see [[CSS-FONTS-4]])
    <li>the 'color' and 'opacity' properties (see [[CSS-COLOR-4]])
    <li>all background properties (see [[CSS-BACKGROUNDS-4]])
    <li>any typesetting properties that apply to inline elements (see [[CSS-TEXT-4]])
    <li>all text decoration properties (see [[CSS-TEXT-DECOR-4]])
    <li>any inline layout properties that apply to inline elements (see [[CSS-INLINE-3]])
    <li>margin and padding properties (see [[CSS22]])
    <li>border properties and 'box-shadow' (see [[CSS-BACKGROUNDS-4]])
    <li>any other properties defined to apply to ''::first-letter''
        by their respective specifications
  </ul>

  User agents may apply other properties as well.
  However,
  in no case may the application of such unlisted properties to ''::first-letter'' change
  what [=first-letter text=] is represented by that ''::first-letter''.

  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,
  to approximate font sizes;
  and to take the glyph outline into account when performing layout.
  The possibility of such loosely-defined magic has been intentionally removed,
  as it proved to be a poor solution for the intended use case (drop caps and raised caps),
  yet caused interoperability problems.
  See 'initial-letter' in [[CSS-INLINE-3]]
  for explicitly handling drop caps and raised caps.

<h2 id="highlight-pseudos">
Highlight Pseudo-elements</h2>

<h3 id="highlight-selectors">
Selecting Highlighted Content: the ''::selection'', ''::search-text'', ''::target-text'', ''::spelling-error'', ''::grammar-error'', and ''::highlight()'' pseudo-elements</h3>

  <wpt>
    grammar-spelling-errors-001.html
    grammar-spelling-errors-002.html
    highlight-cascade/cascade-highlight-001.html
    highlight-cascade/cascade-highlight-002.html
    highlight-cascade/cascade-highlight-004.html
    highlight-cascade/cascade-highlight-005.html
    highlight-cascade/highlight-cascade-001.html
    highlight-cascade/highlight-cascade-003.html
    highlight-cascade/highlight-cascade-004.html
    highlight-cascade/highlight-cascade-005.html
    highlight-cascade/highlight-cascade-006.xhtml
    highlight-cascade/highlight-cascade-007.html
    highlight-cascade/highlight-cascade-008.html
    highlight-cascade/highlight-cascade-009.html
    highlight-cascade/highlight-currentcolor-computed-inheritance.html
    highlight-cascade/highlight-currentcolor-computed-visited.html
    highlight-cascade/highlight-currentcolor-computed.html
    highlight-cascade/highlight-currentcolor-painting-properties-001.html
    highlight-cascade/highlight-currentcolor-painting-properties-002.html
    highlight-cascade/highlight-currentcolor-painting-text-shadow-001.html
    highlight-cascade/highlight-currentcolor-painting-text-shadow-002.html
    highlight-cascade/highlight-currentcolor-root-explicit-default-001.html
    highlight-cascade/highlight-currentcolor-root-explicit-default-002.html
    highlight-cascade/highlight-currentcolor-root-implicit-default-001.html
    highlight-cascade/highlight-currentcolor-root-implicit-default-002.html
    highlight-cascade/highlight-pseudos-computed.html
    highlight-cascade/highlight-pseudos-inheritance-computed-001.html
    highlight-cascade/highlight-pseudos-visited-computed-001.html
    highlight-custom-properties-dynamic-001.html
    highlight-painting-005-crash.html
    highlight-painting-currentcolor-001.html
    highlight-painting-currentcolor-001a.html
    highlight-painting-currentcolor-002.html
    highlight-painting-currentcolor-002a.html
    highlight-painting-currentcolor-002b.html
    highlight-painting-currentcolor-003.html
    highlight-painting-currentcolor-003a.html
    highlight-painting-currentcolor-003b.html
    highlight-painting-currentcolor-004.html
    highlight-painting-currentcolor-004a.html
    highlight-painting-currentcolor-004b.html
    highlight-painting-currentcolor-005.html
    highlight-painting-shadows-horizontal.html
    highlight-painting-shadows-vertical.html
    highlight-painting-soft-hyphens-001.html
    highlight-painting-soft-hyphens-002-crash.html
    highlight-styling-001.html
    highlight-styling-002.html
    parsing/highlight-pseudos.html
  </wpt>

  The <dfn export lt="highlight pseudo-element">highlight pseudo-elements</dfn>
  represent portions of a document that have been given a particular status
  and are typically styled differently to indicate that status to the user.
  For example,
  selected portions of the document are typically highlighted
  (given alternate background and foreground colors, or a color wash)
  to indicate their selected status.
  The following <a>highlight pseudo-elements</a> are defined:

  <dl export>
    <dt><dfn>::selection</dfn>
    <dd>
      The ''::selection'' [=pseudo-element=] represents
      the portion of a document that has been selected
      as the target or object of some possible future user-agent operation(s).
      It applies, for example, to selected text within an editable text field,
      which would be copied by a copy operation or replaced by a paste operation.

      <wpt>
      active-selection-001-manual.html
      active-selection-002-manual.html
      active-selection-004-manual.html
      active-selection-011.html
      active-selection-012.html
      active-selection-014.html
      active-selection-016.html
      active-selection-018.html
      active-selection-025.html
      active-selection-027.html
      active-selection-056.html
      active-selection-057.html
      active-selection-063.html
      selection-background-color-001.html
      selection-link-001.html
      selection-link-002.html
      selection-link-003.html
      selection-over-highlight-001.html
      selection-universal-shadow-dom.html
      selection-contenteditable-011.html
      selection-input-011.html
      selection-textarea-011.html
      svg-text-selection-fill-only.html
      svg-text-selection-shadow.html
      svg-text-selection-stroke-only.html
      svg-text-selection-transparent-background.html
      textpath-selection-011.html
      </wpt>

    <dt><dfn>::search-text</dfn>
    <dd>
       The ''::search-text'' [=pseudo-element=] represents text
       identified by the user agent’s find-in-page feature.
       Since not all UAs style matched text in ways
       expressible with the [=highlight pseudo-elements=],
       this pseudo-element is optional to implement.

       The '':current'' [=pseudo-class=] (but not ''::current()'')
       may be combined with ''::search-text''
       to represent the currently focused match instance.
       The '':past'' and '':future'' [=pseudo-classes=] are reserved
       for analogous use in the future.
       Any unsupported combination of these pseudo-classes with ''::search-text''
       <em>must</em> be treated as invalid.

    <dt><dfn>::target-text</dfn>
    <dd>
      The ''::target-text'' [=pseudo-element=] represents text
      directly targeted by the document URL’s [=url/fragment=], if any.

      Note: When a [=url/fragment|URL fragment=] targets an element,
      the '':target'' pseudo-element can be used to select it,
      but ''::target-text'' does not match anything.
      It only matches text that is itself targeted by the [[=url/fragment=]].

      <wpt>
        target-text-001.html
        target-text-002.html
        target-text-003.html
        target-text-004.html
        target-text-005.html
        target-text-006.html
        target-text-007.html
        target-text-008.html
        target-text-009.html
        target-text-010.html
        target-text-dynamic-001.html
        target-text-dynamic-002.html
        target-text-dynamic-003.html
        target-text-dynamic-004.html
        target-text-shadow-horizontal.html
        target-text-shadow-vertical.html
        target-text-text-decoration-001.html
      </wpt>

    <dt><dfn>::spelling-error</dfn>
    <dd>
      The ''::spelling-error'' [=pseudo-element=] represents
      a portion of text that has been flagged by the user agent as misspelled.

      <wpt>
      spelling-error-001.html
      spelling-error-002-manual.html
      spelling-error-003-manual.html
      spelling-error-004-crash.html
      spelling-error-005-crash.html
      spelling-error-006.html
      </wpt>

    <dt><dfn>::grammar-error</dfn>
    <dd>
      The ''::grammar-error'' [=pseudo-element=] represents
      a portion of text that has been flagged by the user agent as grammatically incorrect.

      <wpt>
      grammar-error-001.html
      grammar-error-002-manual.html
      grammar-error-003-manual.html
      </wpt>

    <dt><dfn>::highlight(<<custom-ident>>)</dfn>
    <dd>
      The ''::highlight()'' [=functional pseudo-element=] represents
      the portion of the document associated with the [=custom highlight=]
      identified by the given [=custom highlight name=].
      The <<custom-ident>> argument is required.
      See [[CSS-HIGHLIGHT-API-1]] for details.
  </dl>

  The <a>highlight pseudo-elements</a>
  do not necessarily fit into the element tree,
  and can arbitrarily cross element boundaries without honoring its nesting structure.

<h3 id="highlight-styling">
Styling Highlights</h3>

  The <a>highlight pseudo-elements</a> can only be styled
  by a limited set of properties that do not affect layout
  and can be applied performantly in a highly dynamic environment--
  and additionally (to ensure interoperability)
  whose rendering within the [[#highlight-bounds|required area]]
  is not dependent on the exact (UA-determined) bounds
  of the [=highlight overlay=].

  The following properties apply to the <a>highlight pseudo-elements</a>:

  <ul>
    <li>'color'
    <wpt>
    active-selection-001-manual.html
    active-selection-011.html
    active-selection-016.html
    active-selection-018.html
    highlight-styling-003.html
    highlight-styling-004.html
    </wpt>

    <li>'background-color'
    <wpt>
    active-selection-002-manual.html
    active-selection-012.html
    active-selection-031.html
    </wpt>

    <li>'text-decoration' and its associated properties (including 'text-underline-position' and 'text-underline-offset')
    <wpt>
    active-selection-004-manual.html
    active-selection-014.html
    active-selection-021.html
    grammar-error-001.html
    grammar-error-002-manual.html
    grammar-error-003-manual.html
    spelling-error-001.html
    spelling-error-002-manual.html
    spelling-error-003-manual.html
    </wpt>

    <li>'text-shadow'
    <wpt>
      marker-text-shadow.html
    </wpt>

    <li>'stroke-color', 'fill-color', and 'stroke-width'
    <wpt>
    highlight-styling-003.html
    textpath-selection-011.html
    </wpt>

    <li>[=custom properties=] [[!CSS-VARIABLES-1]]
    <wpt>
    highlight-styling-005.html
    </wpt>
  </ul>

  Issue: Are there any other properties that should be included here?

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

  Note: The 'color' property sets the color of
  both the text
  and all line decorations (underline, overline, line-through)
  and emphasis marks ('text-emphasis')
  applied to the text
  by the <a>originating element</a> and its ancestors and descendants.

  For any properties not listed above,
  but which are required to resolve the values of applicable properties,
  their [=computed values=] are copied from those of the [=originating element=],
  ignoring any values specified on the [=highlight pseudo-element=] itself.
  For example:

  <ul>
    <li>'forced-color-adjust' (used in [=forced colors mode=] to resolve colors)
      and 'color-scheme' (used to resolve <<system-color>> values)
    <li>'font-size', 'font-family', etc. (used to resolve ''em'' and other [=font-relative lengths=]).
    <li>'line-height' (used to resolve ''lh'' units)
    <li>[=custom properties=] [[!CSS-VARIABLES-1]] (used in ''var()'' substitutions)
  </ul>

<!-- Add this back if for some reason someone wants to implement 'outline'?
  The outline, if supported, must be drawn
  around the union of the active portions of the <a>highlight overlay</a>
  precisely along the boundaries of those portions
  and not between congruent parts.
  The UA may use the outline styling of the nearest common ancestor
  of any continuous or discontinuous range
  rather than piecing together varying styles of outline
  into a single shape.
-->

  If, for a given [=highlight pseudo-element=],
  there are colors specified in the [=author origin=],
  those colors must be respected as specified;
  i.e. the UA must not apply any extra processing
  (such as using semi-transparent washes).
  However if there are no colors in the [=author origin=],
  the UA may apply additional color processing.

  Note: This is to ensure that color contrast is preserved
  across all user agents interpreting a given author stylesheet.

  Vendor-prefixed properties such as '-webkit-text-fill-color'
  are not applicable to the [=highlight pseudo-elements=].
  <!-- https://github.com/w3c/csswg-drafts/issues/7580 -->

<h3 id=highlight-ua-styles>
Default UA Styles</h3>

  The following additions are recommended for the default UA stylesheet:
  <pre class="lang-css">
    /* Represent default spelling/grammar error styling in an adjustable way */
    :root::spelling-error { text-decoration: spelling-error; }
    :root::grammar-error  { text-decoration: grammar-error; }
  </pre>

  Some [=highlight pseudo-elements=]
  should have <dfn>paired default highlight colors</dfn>--
  a default 'color' and 'background-color'
  provided by the UA
  that are either used or overridden together,
  see [[#paired-defaults]].
  For ''::selection'' they should correspond to
  ''HighlightText'' and ''Highlight'',
  while for ''::target-text'' they should correspond to
  ''MarkText'' and ''Mark''.

  UAs may apply additional effects to enhance the presentation
  of highlighted content,
  for example dimming content other than the highlighted text
  or transitioning out a highlight style based on user interactions or timing.
  These are not controlled by CSS.

  ISSUE: UA tweaks to the presentation of highlights
  in ways that <em>are</em> controlled by CSS
  are currently under discussion
  in <a href='https://github.com/w3c/csswg-drafts/issues/6853'>Issue 6853</a>.

<h4 id="paired-defaults">
Paired Defaults</h4>

  For compatibility reasons,
  [=paired default highlight colors=]
  must only be [=used value|used=]
  when neither 'color' nor 'background-color'
  yield a [=cascaded value=]
  from the [=author origin=]
  (or inherit their value from the author origin).
  When a highlight color is ''revert'' or ''revert-layer'',
  the origin <em>after</em> rolling back the cascade
  determines the [=cascaded value=]’s [=cascade origin|origin=].

  Note: Because this rule is for compatibility reasons,
  it does not apply to other similar properties
  like 'fill-color' or 'stroke-color'.

  <div class="example">
    For example,
    given the following markup:
    <pre class="lang-markup">
      &lt;p>Highlight this &lt;em>and this&lt;/em>.&lt;/p>
    </pre>
    Any of the following rules
    would suppress the default 'background-color'
    for ''::selection''
    in the <code>&lt;em></code> element
    if given by the author:
    <pre class="lang-css">
      em::selection { color: initial; }
      em::selection { color: inherit; }
      em::selection { color: unset; }
      em::selection { color: green; }
      p::selection { color: green; }
    </pre>
  </div>

  <wpt>
  highlight-cascade/highlight-paired-cascade-001.html
  highlight-cascade/highlight-paired-cascade-002.html
  highlight-cascade/highlight-paired-cascade-003.html
  highlight-cascade/highlight-paired-cascade-004.html
  highlight-cascade/highlight-paired-cascade-005.html
  highlight-cascade/highlight-paired-cascade-006.html
  </wpt>

<h3 id=highlight-bounds>
Area of a Highlight</h3>

  <p>For each type of highlighting (see [[#highlight-selectors]])
  there exists a single <dfn>highlight overlay</dfn> for the entire document,
  the active portions of which are represented
  by the corresponding <a>highlight pseudo-element</a>.
  Each box owns the piece of the overlay corresponding to any text or replaced content
  directly contained by the box.

  <ul>
    <li>
      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 area,
      in which case it belongs to the innermost element that contains both characters
      and is selected when both characters are selected.
      <wpt>
      selection-intercharacter-011.html
      selection-intercharacter-012.html
      </wpt>
    <li>
      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.
      <wpt>
      active-selection-043.html
      </wpt>
    <li>
      The overlay may also include other areas within the border-box of an element;
      in this case, those areas belong to the innermost such element that contains the area.
    <li>
      For an [=inline-level box=], the overlay may extend outside its border edges
      in the [=block axis=] as far as the edges of its [=line box=].
  </ul>

  Issue: See
  <a href="http://lists.w3.org/Archives/Public/www-style/2008Nov/0022.html">F2F minutes</a>,
  <a href="http://lists.w3.org/Archives/Public/www-style/2008Oct/0268.html">dbaron's message</a>,
  <a href="http://lists.w3.org/Archives/Public/www-style/2010May/0247.html">Daniel's thread</a>,
  <a href="http://lists.w3.org/Archives/Public/www-style/2010May/0261.html">Gecko notes</a>,
  <a href="http://lists.w3.org/Archives/Public/www-style/2010May/0366.html">Opera notes</a>,
  <a href="http://lists.w3.org/Archives/Public/www-style/2010May/0280.html">Webkit notes</a>

  Issue: Not sure if this is the correct way of describing the way things work.

<h3 id=highlight-cascade>
Cascading and Per-Element Highlight Styles</h3>

  Each element draws its own active portions of the <a>highlight overlays</a>,
  which receives the styles specified by
  the corresponding <a>highlight pseudo-element</a> styles
  for which that element is the <a>originating element</a>.
  When multiple styles conflict,
  the winning style is determined by the cascade.

  When any supported property is not given a value by the cascade,
  or given a value of ''inherit'' or ''unset'',
  its [=specified value=] is determined by inheritance from
  the corresponding <a>highlight pseudo-element</a>
  of its <a>originating element</a>'s parent element.
  This occurs regardless of whether that property is an <a>inherited property</a>.

  Additionally, for [=highlight pseudo-elements=] originating from the [=root element=]
  the inherited value of 'color' is ''currentColor'', not the [=initial value=].

  All [=custom properties=] inherit from the <a>originating element</a>,
  regardless of whether that property is a [=custom property=]
  that is registered to [=CSS/inherit=] or not.

  <wpt>
  active-selection-051.html
  active-selection-052.html
  active-selection-053.html
  active-selection-054.html
  highlight-cascade/cascade-highlight-004.html
  highlight-cascade/highlight-cascade-010.html
  </wpt>

  <div class="example">
    For example, if the following rules were applied:
    <pre class="lang-css">
      p::selection      { color: yellow; background: green; }
      p > em::selection { color: orange; }
      em::selection     { color:    red; }
    </pre>
    to the following markup:
    <pre class="lang-markup">
      &lt;p>Highlight this &lt;em>and this&lt;/em>.&lt;/p>
    </pre>
    The selection highlight would be green throughout,
    with yellow text outside the <code>&lt;em></code> element
    and orange text inside it.
  </div>

  <wpt>
  highlight-cascade/cascade-highlight-001.html
  </wpt>

  <p class="advisement">
  Authors wanting multiple selections styles should use
  <strong>'':root::selection''</strong>
  for their document-wide selection style,
  since this will allow clean overriding in descendants.
  ''::selection'' alone applies to every element in the tree,
  overriding the more specific styles of any ancestors.

  <div class="example">
    For example, if an author specified
    <pre class="lang-css">
      ::selection          { background: blue; }
      p.warning::selection { background:  red; }
    </pre>
    and the document included
    <pre class="lang-markup">
      &lt;p class="warning">Some &lt;strong>very important information&lt;/strong>&lt;/p>
    </pre>
    The highlight would be blue over “very important information”
    because the <code>&lt;strong></code> element´s ''::selection''
    also matches the ''::selection { background: blue; }'' rule.
    (Remember that ''*'' is implied when a tag selector is missing.)
    The style rules that would give the intended behavior
    (red highlight within <code>p.warning</code>, blue elsewhere) are
    <pre class="lang-css">
      :root::selection     { background: blue; }
      p.warning::selection { background:  red; }
    </pre>
  </div>

  <wpt>
  highlight-cascade/cascade-highlight-002.html
  </wpt>

  The following example demonstrates the inheritance of [=custom properties=].

  <div class="example">
    For example, if an author specified
    <pre class="lang-css">
     :root {
        --background-color: green;
        --decoration-thickness: 10px;
        --decoration-color: purple;
      }
      ::selection {
        --decoration-thickness: 1px;
        --decoration-color: green;
      }
      div::selection {
        --decoration-color: blue;
        background-color: var(--background-color, red);
        text-decoration-line: underline;
        text-decoration-style: line;
        text-decoration-thickness: var(--decoration-thickness, 5px);
        text-decoration-color: var(--decoration-color, red);
      }
    </pre>
    The universal ''::selection'' uses the user-agent's default styling
    because it only defines custom properties,
    with no properties that influence the appearance.
    A div's selection highlight would apply a green background to the selected content,
    with a 10px thick blue underline.
    Since ''--background-color'' and ''--decoration-thickness'' custom properties
    are not specified on the ''div::selection'' peudo-element,
    they are inherited from its originating <{div}> element,
    which itself inherits the custom properties from the root.
    However since ''--decoration-color'' is specified on the ''div::selection'' itself,
    its value from the [=originating element=] is not used.
  </div>

  Note: This behavior allows control of selection with custom properties
  in a way that is compatible with pre-existing implementations.

  <wpt>
  highlight-cascade/highlight-cascade-011.html
  </wpt>

<h3 id="highlight-painting">
Painting the Highlight</h3>

  <wpt>
  active-selection-014.html
  active-selection-041.html
  active-selection-045.html
  highlight-painting-001.html
  highlight-painting-002.html
  highlight-painting-003.html
  highlight-painting-004.html
  </wpt>

<h4 id="highlight-backgrounds">
Backgrounds</h4>

  Each <a>highlight pseudo-element</a> draws its background
  over the corresponding portion of the <a>highlight overlay</a>,
  painting it
  immediately below any positioned descendants
  (i.e. just before step 8 in <a href="https://www.w3.org/TR/CSS22/zindex.html#painting-order">CSS2.2&sect;E.2</a>).
  <!-- Its outline, if any, is painted immediately over its background. -->
  The ''::selection'' overlay is drawn
  over the ''::target-text'' overlay which is drawn
  over the ''::spelling-error'' overlay
  which is drawn over the ''::grammar-error'' overlay
  which is drawn over the ''::highlight'' overlays.
  The ''::search-text'' overlay is drawn directly over or below
  the '':selection'' overlay depending on the UA,
  and drawn over all other overlays.

  <wpt>
  selection-overlay-and-grammar-001.html
  selection-overlay-and-spelling-001.html
  highlight-z-index-001.html
  highlight-z-index-002.html
  selection-background-painting-order.html
  </wpt>

<h4 id="highlight-shadows">
Shadows</h4>

  Any 'text-shadow' applying to a [=highlight pseudo-element=]
  is drawn over its corresponding [=highlight overlay=] background.
  Such text shadows also stack over each other
  (and over any original 'text-shadow' applied to the text and its decorations,
  which continues to apply).

  Note: Since each [=highlight overlay=] background
  is drawn over any shadows belonging to the layer(s) below,
  a [=highlight overlay=] background can obscure lower-level shadows.

<h4 id="highlight-text">
Text and Text Decorations</h4>

  A <a>highlight pseudo-element</a>
  suppresses the normal drawing of any associated text,
  and the text decorations
  (other than shadows)
  that had been applied to that text.
  Instead the topmost active <a>highlight overlay</a>
  redraws that text
  (and those decorations)
  over all the <a>highlight overlay</a> backgrounds
  <!-- (and outlines, if any) -->
  using that highlight’s own 'color'.

  Note: This means that unlike shadows,
  line decorations and emphasis marks
  won’t be obscured by any highlight overlay backgrounds
  that are drawn for the associated text.

  For this purpose,
  ''currentColor'' on a [=highlight pseudo-element=]’s 'color' property represents
  the 'color' of the next <em>active</em> <a>highlight pseudo-element</a> layer below,
  falling back finally to the colors that would otherwise have been used
  (those applied by the [=originating element=] or
  an intervening [=pseudo-element=] such as ''::first-line'' or ''::first-letter'').

  Note: The element’s own text decorations
  (both <a href="https://www.w3.org/TR/css-text-decor/#line-decoration">line decorations</a>
  and <a href="https://www.w3.org/TR/css-text-decor/#emphasis-marks">emphasis marks</a>)
  are thus drawn in the pseudo-element’s own 'color'
  when that is not ''currentColor'',
  regardless of their original color or fill specifications.

  Any text decorations introduced by each <a>highlight pseudo-element</a>
  are stacked in the same order as their backgrounds
  over the text’s original decorations
  and are all drawn, each decoration in its own color.
  The normal painting order applies,
  so as per <a href="https://www.w3.org/TR/CSS2/zindex.html#painting-order">CSS2 Appendix E</a>,
  all underlines are drawn
  below overlines which are drawn
  below the text which is drawn
  below any line-throughs.
  However, text decorations applied by ''::selection''
  may instead all be drawn
  along with the text
  as a topmost set of layers
  above all other decorations.

  <div class="example">
    For example, assuming the original text has an underline and a strike-through,
    that ''::selection'' applies an underline
    and ''::target-text'' applies both overline and strike-through,
    the following are both conformant painting orders:
    <div style="columns: 20em">
      <ol style="break-inside: avoid; margin-top: 0;">
        <li>original underline
        <li>''::selection'' underline
        <li>''::target-text'' overline
        <li>''::selection''-colored text
        <li>original strike-through
        <li>''::target-text'' strike-through
      </ol>
      <ol style="break-inside: avoid; margin-top: 0;">
        <li>original underline
        <li>''::target-text'' overline
        <li>original strike-through
        <li>''::target-text'' strike-through
        <li>''::selection'' underline
        <li>''::selection''-colored text
      </ol>
    </div>
  </div>

  <a href="https://www.w3.org/TR/css-text-decor/#line-decoration">Line decorations</a> introduced by [=highlight pseudo-elements=]
  apply only to the text associated with their [=originating element=],
  and are not propagated to descendants
  except via property [=inheritance=] (as described [[#highlight-cascade|above]]).

  Note: Unlike the originating element’s own decorations,
  decorations declared on a highlight pseudo-element
  propagate to [=out-of-flow|out-of-flow elements=] and [=inline blocks=],
  with thickness and position varying between descendants.

  <wpt>
  selection-originating-underline-order.html
  selection-originating-decoration-color.html
  selection-originating-strikethrough-order.html
  </wpt>

<h4 id="highlight-replaced">
Replaced Elements</h4>

  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 of the specified 'color';
  however the UA may adjust the alpha channel.

  <wpt>
  selection-paint-image.html
  </wpt>

<h3 id="highlight-security">
Security Considerations for Highlighting</h3>

  Because the styling of spelling and grammar errors
  can leak information about the contents of a user's dictionary
  (which can include the user's name and even includes the contents of their address book!)
  UAs that implement ''::spelling-error'' and ''::grammar-error''
  must mitigate the following attacks:
  <ul>
    <li>Pages attempting to directly read the styling of highlighted segments.
    <li>Pages attempting to track performance impacts of styling highlighted segments via programatic modification of text fields.
  </ul>

<h2 id="treelike">
Tree-Abiding Pseudo-elements</h2>

  <dfn export local-lt="tree-abiding" id="tree-abiding">Tree-abiding pseudo-elements</dfn> always fit within the box tree.
  They <a lt="inheritance">inherit</a> any inheritable properties from their <a>originating element</a>;
  non-inheritable properties take their <a>initial values</a> as usual.
  [[CSS-CASCADE-4]]
  A subset of these are the <dfn export local-lt="fully styleable" id="fully-styleable">fully styleable pseudo-elements</dfn>;
  all properties that apply to a real element
  also apply to a [=fully styleable pseudo-element=].

  <wpt>
    parsing/tree-abiding-pseudo-elements.html
  </wpt>

<h3 id="generated-content">
Generated Content Pseudo-elements: ''::before'' and ''::after''</h3>

  When their computed 'content' value is not ''content/none'',
  these [=pseudo-elements=] generate boxes
  as if they were immediate children of their <a>originating element</a>,
  with content as specified by 'content'.

  <dl>
    <dt><dfn>::before</dfn>
    <dd>Represents a styleable child pseudo-element
    immediately before the <a>originating element</a>'s actual content.

    <dt><dfn>::after</dfn>
    <dd>Represents a styleable child pseudo-element
    immediately after the <a>originating element</a>'s actual content.
  </dl>

  <wpt>
    before-after-dynamic-custom-property-001.html
    before-as-flex-container.html
    before-dynamic-display-none.html
    before-in-display-none-thcrash.html
    before-preceding-whitespace-dynamic.html
    focus-visible-originating-element.html
  </wpt>

  Both ''::before'' and ''::after''
  are [=fully styleable pseudo-elements=]:
  there is no restriction on what properties apply to them.

  <div class="example">
    For example, the following rule inserts the string “Note: ”
    before the content of every <code>&lt;p></code> element
    whose <code>class</code> attribute has the value <code>note</code>:

    <pre class="lang-css">p.note::before { content: "Note: " }</pre>

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

  As with the content of regular elements,
  the generated content of ''::before'' and '':after'' pseudo-elements
  can form part of any ''::first-line'' and ''::first-letter'' pseudo-elements
  applied to its <a>originating element</a>.
  Also as with regular child elements,
  the ''::before'' and ''::after'' pseudo-elements
  are suppressed when their parent, the [=originating element=],
  is [=replaced element|replaced=].

  <wpt>
  pseudo-replaced-elements.html
  </wpt>

<h3 id="marker-pseudo">
List Markers: the ''::marker'' pseudo-element</h3>

  The <dfn>::marker</dfn> [=pseudo-element=] represents
  the automatically generated [=marker box=] of a [=list item=].
  (See [[CSS-DISPLAY-3]] and [[CSS-LISTS-3]].)

  <wpt>
    marker-and-other-pseudo-elements.html
    marker-animate-002.html
    marker-animate.html
    marker-color.html
    marker-computed-content.html
    marker-computed-size.html
    marker-content-001.html
    marker-content-001b.html
    marker-content-001c.html
    marker-content-002.html
    marker-content-003.html
    marker-content-003b.html
    marker-content-004.html
    marker-content-005.html
    marker-content-006.html
    marker-content-010.html
    marker-content-012.html
    marker-content-013.html
    marker-content-014.html
    marker-content-015.html
    marker-content-016.html
    marker-content-017.html
    marker-content-018.html
    marker-content-019.html
    marker-content-020.html
    marker-content-021.html
    marker-content-022.html
    marker-content-023.html
    marker-content-024.html
    marker-default-styles.html
    marker-display-computed.html
    marker-display-dynamic-001.html
    marker-font-properties.html
    marker-font-variant-numeric-default-ref.html
    marker-font-variant-numeric-default.html
    marker-font-variant-numeric-normal-ref.html
    marker-font-variant-numeric-normal.html
    marker-hit-testing.html
    marker-hyphens.html
    marker-inherit-line-height.html
    marker-inherit-values.html
    marker-intrinsic-contribution-001.html
    marker-intrinsic-contribution-002.html
    marker-letter-spacing.html
    marker-line-break.html
    marker-line-height.html
    marker-list-style-position.html
    marker-overflow-wrap.html
    marker-reverted-styles.html
    marker-tab-size.html
    marker-text-align-001.html
    marker-text-align-002.html
    marker-text-align-003.html
    marker-text-combine-upright.html
    marker-text-decoration-skip-ink.html
    marker-text-emphasis.html
    marker-text-transform-default.html
    marker-text-transform-dynamic.html
    marker-text-transform-uppercase.html
    marker-unicode-bidi-default-ref.html
    marker-unicode-bidi-default.html
    marker-unicode-bidi-normal-ref.html
    marker-unicode-bidi-normal.html
    marker-variable-computed-style.html
    marker-variable.html
    marker-word-break.html
    marker-word-spacing.html
    outside-marker-paint-order.html
    parsing/marker-supported-properties-in-animation.html
    parsing/marker-supported-properties.html
  </wpt>

  <!-- under discussion in https://github.com/w3c/csswg-drafts/issues/1442 and https://github.com/w3c/csswg-drafts/issues/4506
  Inheritance for a ''::marker'' pseudo-element ignores any ''::first-line'' styles -->
  The contents of a ''::marker'' are ignored (not selected) by ''::first-letter''.

  ISSUE: Interaction of ''::marker'' and ''::first-line'' is currently under discussion in <a href='https://github.com/w3c/csswg-drafts/issues/4506'>Issue 4506</a>.

  ''::marker'' is a [=tree-abiding pseudo-element=],
  but is not [=fully styleable=];
  only a limited set of properties can be used on the ''::marker'' pseudo-element.
  This list is defined in [[css-lists-3#marker-properties]].

  The  ''::before::marker'' or ''::after::marker'' selectors
  are valid and
  can be used to represent the [=marker boxes=]
  of ''::before'' or ''::after'' pseudo-elements that happen to be [=list items=].
  However ''::marker::marker'' is invalid,
  and the computed value of 'display' on ''::marker''
  always loses any ''display/list-item'' aspect.

  ISSUE: Should ''::marker'' also have ''::prefix'' and ''::suffix'' sub-elements?

<h3 id="placeholder-pseudo">
Placeholder Input: the ''::placeholder'' pseudo-element</h3>

  The <dfn>::placeholder</dfn> [=pseudo-element=] represents
  placeholder text in an input field:
  text that represents the input
  and provides a hint to the user on how to fill out the form.
  For example, a date-input field
  might have the placeholder text “YYYY/MM/DD”
  to clarify that numeric dates are to be entered in year-month-day order.
  It is a [=tree-abiding pseudo-element=].

  <wpt>
    placeholder-as-multicol-crash.html
    placeholder-excluded-properties.html
    placeholder-inherit.html
    placeholder-input-dynamic-crash.html
    placeholder-input-number.html
  </wpt>

  <div class="example">
    For example, according to the semantics of [[HTML]]
    the <{input/placeholder}> attribute on the <{input}> and <{textarea}> elements
    provide placeholder text.
    The ''::placeholder'' [=pseudo-element=]
    represents such text when it is displayed.
  </div>

  Note: There also exists a '':placeholder-shown'' pseudo-<em>class</em>,
  which applies to (real) elements while they are showing placeholder text,
  and can be used to style such elements specially.
  ''::placeholder'' specifically represents the placeholder <em>text</em>,
  and is thus relatively limited in its abilities.

  All properties that apply to the ''::first-line'' pseudo-element
  also apply to the ''::placeholder'' pseudo-element,
  except those defined in [[!CSS-INLINE-3]].

  In interactive media, placeholder text is often hidden once the user has entered input;
  however this is not a requirement, and both the input value and the placeholder text may be visible simultaneously.
  The exact behavior is UA-defined.
  Note that in static media (such as print)
  placeholder text will be present even after the user has entered input.

  Issue: Authors seem to want 'text-align' on the list of supported properties.
  See e.g. <a href="http://css-tricks.com/almanac/selectors/p/placeholder/">comments here</a>.

  Note: It's been requested that ''::placeholder'' also refer to
  a placeholder which has a corresponding element in the element tree.
  It's not clear how this should work, but it may be worth doing.
  See <a href="https://github.com/w3c/csswg-drafts/issues/2517">Issue 2417</a>.

<h2 id="element-like" oldids=part-like>
Element-backed Pseudo-Elements</h2>

  The <dfn export lt="element-backed|element-backed pseudo-element">element-backed pseudo-elements</dfn>,
  interact with most CSS and other platform features
  as if they were real elements
  (and, in fact, often <em>are</em> real elements
  that are not otherwise selectable).

  Element-backed pseudo-elements are always [=tree-abiding=].
  Unless otherwise specified,
  they are [=fully styleable=]
  and inherit from their [=originating element=],
  just like standard [=tree-abiding pseudo-elements=];
  but they can be defined to inherit from another element instead.
  (For example, ''::part()'' inherits from
  the parent of the element it represents in the shadow tree.)

  All [=pseudo-classes=] and [=pseudo-elements=]
  are syntactically allowed after an [=element-backed pseudo-element=]
  (such as ''x-button::part(label):hover''
  or ''x-button::part(label)::before''),
  just as if the pseudo-element were a [=type selector=];
  but some are disallowed from matching:

  * The [=structural pseudo-classes=],
    '':has()'' pseudo-class,
    '':scope'' pseudo-class,
    and '':host''/'':host()''/'':host-context()'' pseudo-classes
    never match.
  * ''::part()'' never matches. (Other [=element-backed pseudo-elements=] can, however.)

  An [=element-backed pseudo-element=] can define itself as representing a real element
  (possibly one not accessible in the current tree).
  If it does so,
  all pseudo-classes and pseudo-elements not otherwise disallowed (see above)
  match as they would on that real element.
  If it does not do so,
  it must define which pseudo-classes it matches and when;
  however, unless otherwise specified,
  any pseudo-classes allowed on [=tree-abiding pseudo-elements=]
  are always allowed on [=element-backed pseudo-elements=].


<h3 id="file-selector-button-pseudo">
File Selector Button: the ''::file-selector-button'' pseudo-element</h3>

  The <dfn>::file-selector-button</dfn> [=pseudo-element=]
  targets the ''&lt;button>''
  inside an ''&lt;input>'' element with <code>type=file</code>,
  if the UA renders such a button.

  <wpt>
    file-selector-button-001.html
    file-selector-button-after-part.html
    file-selector-button-display-none-overflow-crash.html
    file-selector-button-display-toggle-crash.html
    file-selector-button-float.html
    file-selector-button-inherit.html
  </wpt>

  There is no restriction on which properties apply to the
  ''::file-selector-button'' pseudo-element.

  <div class="example" id="file-selector-button-example">
    For example, the following example should show a green border around the
    file selector button:

    <pre class="lang-css">::file-selector-button { border: 3px solid green }</pre>
  </div>

<h3 id="details-content-pseudo">
Expandable contents of details element: the ''::details-content'' pseudo-element</h3>

  The <dfn>::details-content</dfn> [=pseudo-element=] targets
  the additional information in a <{details}> element
  that can be expanded or collapsed.
  It is an [=element-backed pseudo-element=].

  <wpt title="details element">

  </wpt>

  There is no restriction on which properties apply to the
  ''::details-content'' pseudo-element.

  <div class="example" id="details-content-example">
    For example, the following example would
    animate the opacity of the additional information
    when the <{details}> element opens:

    <pre class="lang-css">
      details::details-content {
        opacity: 0;
        transition: content-visibility 300ms allow-discrete, opacity 300ms;
      }

      details[open]::details-content {
        opacity: 1;
      }</pre>
  </div>

  Note: The default UA stylesheet styles a closed ''::details-content''
  with ''content-visibility: hidden'',
  so the contents are still considered present for the purpose of find-in-page
  and similar features.
  This, however, only suppresses the display of the pseudo-elements's <em>contents</em>;
  if margin, borders, etc are set on the pseudo-element, they'll still be visible.
  Use ''[open]::details-content'' to apply these styles if that's undesirable.


<h2 id="interactions">
Overlapping Pseudo-element Interactions</h2>

  <div class="example" id="overlapping-example">
    Recall that
    <ul>
      <li>
        the contents of ''::before'' and ''::after'' are selected
        exactly as if they were normal elements in the document source tree
      <li>
        the ''::first-letter'' boundaries are tightly wrapped around the first letter text,
        and ''::first-letter'' is constrained to exist solely on the first formatted line.
      <li>
        the ''::first-line'' start is inserted just inside the containing block's element boundary,
        and its end after the close of all content on the line
    </ul>

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

    <xmp class="lang-html">
      <style>
      p { color: red; font-size: 12pt }
      p::first-letter { color: green; font-size: 200% }
      p::first-line { color: blue }
      </style>

      <p>Some text that ends up on two lines</p>
    </xmp>

    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 <a>fictional tag sequence</a> for this fragment might be:
    <xmp class="lang-html">
      <p>
        <p::first-line>
          <p::first-letter>
            S
          </p::first-letter>
          ome text that
        </p::first-line>
        ends up on two lines
      </p>
    </xmp>
  </div>

<h2 id="cssom">
Additions to the CSS Object Model</h2>

<wpt>
  idlharness.html
</wpt>

<h3 id="CSSPseudoElement-interface">
{{CSSPseudoElement}} Interface</h3>

  <pre class="idl">
    [Exposed=Window]
    interface CSSPseudoElement {
        readonly attribute CSSOMString type;
        readonly attribute Element element;
        readonly attribute (Element or CSSPseudoElement) parent;
        readonly attribute CSSOMString selectorText;
        CSSPseudoElement? pseudo(CSSOMString type);
    };
  </pre>

  <wpt>
    CSSPseudoElement-identity.html
  </wpt>

  ISSUE: This interface is under design development,
  and this draft is looking for feedback more than implementation.
  The CSSWG would particularly appreciate hearing about use cases and problems.

  The <dfn attribute for=CSSPseudoElement>type</dfn> attribute
  is a string representing the type of the pseudo-element.
  This can be any standardized [=tree-abiding pseudo-element=]
  that is not an [=element-backed pseudo-element=],
  for example:

  <dl>
    <dt><code>"::before"</code>
    <dd>Represents the ''::before'' pseudo-element.
    <dt><code>"::after"</code>
    <dd>Represents the ''::after'' pseudo-element.
    <dt><code>"::marker"</code>
    <dd>Represents the ''::marker'' pseudo-element.
    <dt><code>"::backdrop"</code>
    <dd>Represents the ''::backdrop'' pseudo-element.
    <dt><code>"::view-transition"</code>
    <dd>Represents the ''::view-transition'' pseudo-element.
  </dl>

  The <dfn attribute for=CSSPseudoElement>element</dfn> attribute is the
  [=ultimate originating element=] of the [=pseudo-element=].

  The <dfn attribute for=CSSPseudoElement>parent</dfn> attribute is the
  [=originating element=] of the pseudo-element.
  For most pseudo-elements
  {{CSSPseudoElement/parent}} and {{CSSPseudoElement/element}}
  will return the same {{Element}};
  for [=sub-pseudo-elements=],
  {{CSSPseudoElement/parent}} will return a {{CSSPseudoElement}}
  while {{CSSPseudoElement/element}} returns an {{Element}}.

  The <dfn attribute for=CSSPseudoElement>selectorText</dfn> attribute
  is a string representing the full, normalized selector text
  used to select the pseudo-element.
  This includes the pseudo-element name and any arguments,
  serialized in a form that can round-trip.
  For example, <code>"::after"</code> for a ''::after'' pseudo-element,
  or <code>"::scroll-button(left)"</code> for a ''::scroll-button()'' pseudo-element
  with a <code>left</code> argument.

  The <dfn attribute for=CSSPseudoElement>pseudo(type)</dfn> method
  returns the {{CSSPseudoElement}} interface
  representing the [=sub-pseudo-element=] referenced in its argument,
  if such a [=sub-pseudo-element=] could exist and would be valid,
  and null otherwise.
  See {{Element/pseudo()}} below.

  Note: This interface may be extended in the future
  to other pseudo-element types
  and/or to allow setting style information
  through a {{CSSStyleDeclaration}} <code>style</code> attribute.
  The current functionality is limited
  to that which is needed to support [[web-animations-1]].

<h3 id="window-interface">
{{pseudo()}} method of the {{Element}} interface</h3>

  A new method is added to the {{Element}} interface to retrieve
  [=pseudo-elements=] created by a given element for a given type:
  <pre class="idl">
    partial interface Element {
      CSSPseudoElement? pseudo(CSSOMString type);
    };
  </pre>

  <div algorithm>
    The <dfn method for=Element title="pseudo(type)" id="dom-element-pseudo">pseudo(CSSOMString type)</dfn> method
    is used to retrieve the {{CSSPseudoElement}} instance
    of the type matching {{Element/pseudo(type)/type!!argument}}
    associated with the element.
    When it is called,
    execute the following steps:

    1. [=CSS/Parse=] the {{Element/pseudo(type)/type!!argument}} argument as a <<pseudo-element-selector>>,
      and let |type| be the result.

    2. If |type| is failure,
      return null.

    3. If |type| is an [=element-backed pseudo-element=],
      return null.

    4. If |type| is not a [=tree-abiding pseudo-element=],
      return null.

    5. Otherwise, return the {{CSSPseudoElement}} object
      representing the pseudo-element
      that would match the selector |type|
      with [=this=] as its [=originating element=].
  </div>

  Return values that represent the same [=pseudo-element=]
  on the same [=originating element=]
  must be, insofar as observable,
  always the same {{CSSPseudoElement}} object.
  (The UA may drop or regenerate the object for convenience or performance
  if this is not observable.)

  Note: {{CSSPseudoElement}} is returned even when this method is invoked on elements
  that can't have the requested pseudo type (e.g. ''::before'' on <{input}>).
  See <a href="https://github.com/w3c/csswg-drafts/issues/12159#issuecomment-3005238286">resolution</a> for more details.
  Discussion in <a href="https://github.com/w3c/csswg-drafts/issues/12158">Issue 12158</a> will clarify how to
  determine that the requested pseudo doesn't really "exist".

  ISSUE: The identity, lifetime, and nullness of the return value
  (and potential error cases)
  of the {{pseudo()}} method is still under discussion.
  See <a href="https://github.com/w3c/csswg-drafts/issues/3607">Issue 3607</a>
  and <a href="https://github.com/w3c/csswg-drafts/issues/3603">Issue 3603</a>.

<h3 id="getComputedStyle">
{{Window/getComputedStyle()}}</h3>

When the second parameter <var ignore>pseudoElt</var>
refers to a [=highlight pseudo-element=],
{{Window/getComputedStyle()}} returns styles
as if that highlight is active
and all other highlights are inactive.
This avoids the potential
ambiguity and privacy risks of returning a result
that depends on the actual highlight state.

<h2 id="css2-compat">
Compatibility Syntax</h2>

  <p>For compatibility with existing style sheets written against CSS Level 2 [[CSS2]],
  user agents must also accept the previous one-colon notation
  (<code>:before</code>, <code>:after</code>, <code>:first-letter</code>, <code>:first-line</code>)
  for the ''::before'', ''::after'', ''::first-letter'', and ''::first-line'' pseudo-elements.

<h2 class="no-num" id="security">
Security Considerations</h2>

  <p>
    For highlighting, see [[#highlight-security]].
  </p>

<h2 class="no-num" id="privacy">
Privacy Considerations</h2>

  <p>
    No new privacy considerations have been raised against this module.
  </p>

<h2 class="no-num" id="changes">
Changes</h2>

  Significant changes since the <a href="https://www.w3.org/TR/2022/WD-css-pseudo-4-20221230/">30 December 2022 Working Draft</a> include:

  <ul>
    <li>Defined [=element-backed pseudo-element=] and [=fully styleable pseudo-element=] as terms.
      (<a href="https://github.com/w3c/csswg-drafts/pull/10199">Issue 10199</a>, <a href="https://github.com/w3c/csswg-drafts/issues/10083">Issue 10083</a>)
    <li>Reworked the property (and custom property)
      application and inheritance model for [=highlight pseudo-elements=]
      (Issues <a href="https://github.com/w3c/csswg-drafts/issues/7591">7591</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/7580">7580</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/6641">6641</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/11317">11317</a>)
    <li>Defined ''::highlight()'' and improved cross-referencing to [[CSS-HIGHLIGHT-API-1]].
      (Issue <a href="https://github.com/w3c/csswg-drafts/issues/6755">6755</a>)
    <li>Added ''::search-text'' as a new [=highlight pseudo-element=],
      and allowed it to combine with '':current''.
      (Issues <a href="https://github.com/w3c/csswg-drafts/issues/10212">10212</a>
       <a href="https://github.com/w3c/csswg-drafts/issues/10213">10213</a>,
       and <a href="https://github.com/w3c/csswg-drafts/issues/10298">10298</a>)
    <li>Added ''::details-content'' [=pseudo-element=]
      (<a href="https://github.com/w3c/csswg-drafts/pull/10379">Issue 10379</a>)
    <li>Allow space and no-break space to be part of ''::first-letter''
      when occuring before the [=first letter=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/9413">Issue 9413</a>)
    <li>Renamed ''::postfix'' to ''::suffix''.
      (Issue <a href="https://github.com/w3c/csswg-drafts/issues/11949">Issue 11949</a>)
    <li>Excluded inline layout properties from ''::placeholder''.
      (<a href="https://github.com/w3c/csswg-drafts/issues/5379">Issue 5379</a>)
    <li>Clarified that UAs must not tweak author-specified colors for [=highlight pseudo-elements=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/6853">Issue 6853</a>)
    <li>Clarified that the inherited value of 'color' is ''currentColor'', not the [=initial value=].
  </ul>


  Significant changes since the <a href="https://www.w3.org/TR/2020/WD-css-pseudo-4-20201231/">31 December 2020 Working Draft</a> include:

  <ul>
    <li>Added ''::first-letter::prefix'' and ''::first-letter::postfix'' [=sub-pseudo-elements=]
      to address punctuation associated with the ''::first-letter'' [=pseudo-element=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/2040">Issue 2040</a>)
    <li>Fine-tuned the [=first-letter text=] pattern:
      <ul>
        <li>Excluded word-separating spaces from [=first-letter text=].
          (<a href="https://github.com/w3c/csswg-drafts/issues/5830">Issue 5830</a>)
        <li>Excluded dashes and opening punctuation from following punctuation.
          (<a href="https://github.com/w3c/csswg-drafts/issues/5830">Issue 5830</a>)
        <li>Allowed symbols to represent the [=first letter=].
          (<a href="https://github.com/w3c/csswg-drafts/issues/5099">Issue 5099</a>)
        <li>Clarified that the [=first-letter text=] is truncated by a line break.
          (<a href="https://github.com/w3c/csswg-drafts/issues/2254">Issue 2254</a>)
      </ul>
    <li>Rewrote and clarified definition of '':first-letter'', and improved examples and notes.
    <li>Rewrote and clarified definition of ''::first-line'', and improved examples.
    <li>Defined application of 'line-height' to ''::first-line''.
      (<a href="https://github.com/w3c/csswg-drafts/issues/2282">Issue 2282</a>)
    <li>Defined box structure interaction of ''::first-line'' and ''::first-letter''.
    <li>Defined hierarchy order of ''::first-line'' and the [=root inline box=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/1384">Issue 1384</a>)
    <li>Clarified [[#paired-defaults|paired default]] behavior of [=highlight pseudo-element=] 'color' and 'background-color'.
      (<a href="https://github.com/w3c/csswg-drafts/issues/6386">Issue 6386</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/6774">Issue 6774</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/6779">Issue 6779</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/7837">Issue 7837</a>)
    <li>Defined application of [=forced colors mode=] to [=highlight pseudo-elements=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/7264">Issue 7264</a>)
    <li>Clarified painting order, propagation, and application of [=highlight pseudo-element=] text decorations.
      (<a href="https://github.com/w3c/csswg-drafts/issues/6022">Issue 6022</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/6829">Issue 6829</a>,
       <a href="https://github.com/w3c/csswg-drafts/issues/7101">Issue 7101</a>)
    <li>Removed 'caret-color' and 'cursor' from applying to [=highlight pseudo-elements=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/4100">Issue 4100</a>)
    <li>Clarified interaction of [=highlight pseudo-elements=] and {{Window/getComputedStyle()}}.
      (<a href="https://github.com/w3c/csswg-drafts/issues/6818">Issue 6818</a>)
    <li>Clarified application of [=custom properties=] to [=pseudo-elements=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/6264">Issue 6264</a>)
    <li>

    <li>Extended the {{CSSPseudoElement}} interface
      with a {{CSSPseudoElement/parent}} attribute
      and {{CSSPseudoElement/pseudo()}} method
      to address [=sub-pseudo-elements=].
      (<a href="https://github.com/w3c/csswg-drafts/issues/3836">Issue 3836</a>)
  </ul>

  Significant changes since the <a href="https://www.w3.org/TR/2019/WD-css-pseudo-4-20190225/">25 February 2019 Working Draft</a> include:

  <ul>
    <li>Added ''::target-text'' [=pseudo-element=].
    (<a href="https://github.com/w3c/csswg-drafts/issues/5522">Issue 5522</a>)
    <li>Removed ''::inactive-selection''.
    (<a href="https://github.com/w3c/csswg-drafts/issues/4579">Issue 4579</a>)
    <li>Added ''::file-selectors-button'' [=pseudo-element=].
    (<a href="https://github.com/w3c/csswg-drafts/issues/5049">Issue 5049</a>)
    <li>Adjusted rules for inheritance of properties from ''::first-line''
    to handle inheritable vs non-inheritable properties differently,
    specifically excluded applicability of properties that control [=writing mode=] because they affect the cascade,
    and defined interaction with custom properties.
    (<a href="https://github.com/w3c/csswg-drafts/issues/1097">Issue 1097</a>)
    <li>Added 'ruby-position' to properties allowed on ''::first-line'',
    analogous with 'text-emphasis-position'.
    (<a href="https://github.com/w3c/csswg-drafts/issues/2998">Issue 2998</a>)
    <li>Included spaces between the first letter and its surrounding punctuation in ''::first-letter''.
    (<a href="https://github.com/w3c/csswg-drafts/issues/5154">Issue 5154</a>)
    <li>Defined interaction of ''::marker'' and ''::first-letter''.
    <li>Made ''::before::marker'' and ''::after::marker'' valid.
    (<a href="https://github.com/w3c/csswg-drafts/issues/1793">Issue 1793</a>)
    <li>Moved the <a href="https://www.w3.org/TR/css-lists-3/#marker-properties">list of properties</a> applying to ''::marker'' to [[CSS-LISTS-3]]
    (also adding 'content', 'unicode-bidi', and 'direction').
    <li>Added ''::marker'' to types allowed for {{CSSPseudoElement}} interface.
    (<a href="https://github.com/w3c/csswg-drafts/issues/3763">Issue 3763</a>)
    <li>Clarified return value of {{pseudo()}}.
    (Issues <a href="https://github.com/w3c/csswg-drafts/issues/3603">3603</a> and <a href="https://github.com/w3c/csswg-drafts/issues/3607">3607</a>)
    <li>Allowed highlight overlay of inline-level boxes to extend to the line box edges.
    (Issues <a href="https://github.com/w3c/csswg-drafts/issues/5395">5395</a> and <a href="https://github.com/w3c/csswg-drafts/issues/4624">4624</a>)
    <li>Clarified that ''currentColor'' on a [=highlight pseudo-element=]
    uses the color that would be used if the text were not “highlighted”,
    even if that color was provided by a [=pseudo-element=] like ''::first-line''.
    (<a href="https://github.com/w3c/csswg-drafts/issues/4625">Issue 4625</a>)
    <li>Defined how 'text-shadow' interacts with [=highlight pseudo-elements=].
    (<a href="https://github.com/w3c/csswg-drafts/issues/3932">Issue 3932</a>)
    <li>Improved the [[#highlight-ua-styles|default UA style sheet]] rules applying to highlight pseudo-elements.
  </ul>

  Changes since the <a href="https://www.w3.org/TR/2016/WD-css-pseudo-4-20160607/">7 June 2016 Working Draft</a> include:

  <ul>
    <li>Specified ''spelling-error'' and ''grammar-error'' with ''::spelling-error'' and ''::grammar-error'' in the UA stylesheet.
    <li>Redefined value propagation between parent/child [=highlight pseudo-elements=] to use inheritance rather than cascading. See discussion in and linked from <a href="https://github.com/w3c/csswg-drafts/issues/2474">Issue 2474</a>.
    <li>Refined list of supported properties for [=highlight pseudo-elements=], e.g. adding 'stroke-color'/'fill-color', removing 'outline', etc.
    <li>Clarified how text and text decoration colors are painted for [=highlight pseudo-elements=].
    <li>Added the {{CSSPseudoElement/element}} attribute to the {{CSSPseudoElement}} interface.
    <li>Changed the values of the {{CSSPseudoElement/type}} attribute on the {{CSSPseudoElement}} interface to match the corresponding [=pseudo-elements=].
    <li>Reduced supported types of {{CSSPseudoElement}} and removed unimplemented <code>style</code> attribute.
    <li>Changed <code>window.getPseudoElements(elem,type)</code> to <code>Element.pseudo(type)</code>.
    <li>Miscellaneous minor clarifications and fixes.
  </ul>

<h2 class="no-num" id="acknowledgements">
Acknowledgements</h2>

  The editors would like to specifically thank the following individuals for their
  contributions to this specification:
  Tab Atkins,
  Delan Azabani,
  David Baron,
  Oriol Brufau,
  Razvan Caliman,
  Stephen Chenney,
  Chris Coyier,
  Anders Grimsrud,
  Vincent Hardy,
  François Remy.

  <wpt hidden title="tests in wrong place">
    backdrop-animate-002.html
    backdrop-animate.html
    input-element-pseudo-open.optional.html
    relative-box-order-of-pseudo-elements.html
  </wpt>
  <wpt hidden title="input type=range not standardized yet">
    slider/slider-fill-001.html
    slider/slider-fill-002.html
    slider/slider-fill-003.html
    slider/slider-thumb-001.html
    slider/slider-track-001.html
    slider/slider-track-002.html
    slider/slider-track-003.html
  </wpt>
  <wpt hidden title="misc">
    chrome-bug-1299142-crash.html
    chrome-first-letter-container-query-crash.html
    chrome-first-letter-inside-replaced-crash.html
    firefox-bug-1907238-crash.html
    get-computed-style-crash.html
    svg-text-selection-002.html
    text-selection.html
  </wpt>
