CSS 3 Module <== Test # ==>
W3C Selectors 17 of 19 of the interactive tests category
Testing Date Revision
:focus with ::selection (ID #164) 2001-11-21 1.0

NOTE: User interaction is required for this test.

CONFORMANCE NOTE: If the UA removes the selection when the focus leaves the text, which is also valid behaviour, then the description above is inaccurate. In these cases, the selection should disappear completely when the focus is moved, and when the focus is returned, the selection should not be in the same place as when focus was removed (typically, either the selection will be non-existent, or everything will be selected -- but what is selected is independent of what was selected when the focus was removed).

If the selection is preserved, then the selection should NOT disappear when focus is removed, it should instead turn silver as described.

  textarea { border: solid thick gray; }
  textarea:focus { border: solid thick green; }
  textarea::selection { background: silver; color: black; }
  textarea:focus::selection { background: lime; color: black; }
   <p><textarea rows="5" cols="70">Select some of this text, then change the focus around. While this
text is focussed, the selection should be green. While the focus is
elsewhere, the selection should be silver. The border should at all
times be a darker colour than the selection&#39;s background. Repeat the
test with everything selected.</textarea></p>

   <p>CONFORMANCE NOTE: If the UA
   removes the selection when the focus leaves the text, which is also
   valid behaviour, then the description above is inaccurate. In these
   cases, the selection should disappear completely when the focus is
   moved, and when the focus is returned, the selection should not be
   in the same place as when focus was removed (typically, either the
   selection will be non-existent, or everything will be selected --
   but what is selected is independent of what was selected when the
   focus was removed).</p>

   <p>If the selection is
   preserved, then the selection should NOT disappear when focus is
   removed, it should instead turn silver as described.</p>