Example
Make the selected text red on a yellow background:
::-moz-selection
{ /* Code for Firefox */
color: red;
background: yellow;
}
::selection
{
color: red;
background: yellow;
}
Try it Yourself »
Definition and Usage
The ::selection selector matches the portion of an element that is selected by a user.
Only a few CSS properties can be applied to the ::selection selector: color, background, cursor, and outline.
Note: The ::selection pseudo-element was drafted for CSS Selectors Level 3, but removed before the Recommendation status. So, at the moment, the ::selection pseudo-element is not in any specification. (However, it may be re-added to future CSS specifications.)
Browser Support
Selector | |||||
---|---|---|---|---|---|
::selection | 4.0 | 9.0 | 2.0 -moz- | 3.1 | 10.1 |
CSS Syntax
::selection {
css declarations;
}