::selection CSS Pseudo Element

Description

The ::selection pseudo-element applies style to the text selected by the user. The following properties are allowed in style rules: color, background, background-color, cursor, outline and text-shadow .

Syntax

element::selection { … }

Example

<p class="select">Select this text with your mouse to view the effect of the ::selection pseudo-element.</p>
<p>Now select this text to see how it would normally look.</p>
p.select::selection { 
color: #ff0;
background: #000;
}

Notes

Firefox prior to version 62 uses the non-standard pseudo-element ::-moz-selection.

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
9121?9.51.1
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
3718?X1X