The ::selection CSS pseudo-element applies styles to the portion of a document that has been highlighted by the user (such as with the mouse).

Only a small subset of CSS properties can be used with the ::selection pseudo-element: color, background-color, cursor, outline, text-decoration, text-emphasis-color, and text-shadow. Note that, in particular, background-image is ignored.

text-shadow in ::selection is supported by Chrome, Safari and Firefox 17+.

Though this pseudo-element was in drafts of CSS Selectors Level 3, it was removed during the Candidate Recommendation phase, as it appeared that its behavior was under-specified, especially with nested elements, and interoperability wasn't achieved (based on discussion in the W3C Style mailing list).

The ::selection pseudo-element has been added again in Pseudo-Elements Level 4.


/* Firefox syntax */




<div>This text has special styles when you highlight it.</div>
<p>Also try selecting text in this paragraph.</p>


/* Make selected text gold on a red background */
::-moz-selection {
  color: gold;
  background: red;

::selection {
  color: gold;
  background: red;

/* Make selected text in a paragraph white on a blue background */
p::-moz-selection {
  color: white;
  background: blue;

p::selection {
  color: white;
  background: blue;



Specification Status Comment
CSS Pseudo-Elements Level 4
The definition of '::selection' in that specification.
Working Draft Initial definition

The ::selection CSS pseudo-element was drafted for CSS Selectors Level 3 but removed before it reached the Recommendation status. It was re-added as part of the Pseudo-Elements Level 4 draft.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1 (Yes) 1.0 -moz[1] 9 9.5 1.1
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? (Yes) ? ? ? ?

[1] Gecko currently only supports the prefixed version ::-moz-selection. It will be unprefixed in bug 509958.

Document Tags and Contributors

 Last updated by: mfluehr,