::selection 2vu2t
The ::selection CSS pseudo-element represents a portion of the document that is highlighted by the . For example, a portion of a page that is selected by the using the mouse or any other pointing device. 495a4i

::selection
, you can change that to match the overall style or theme of the page.
Only a subset of all CSS properties can be used to style a ::selection
, namely the CSS text-shadow
properties.
You can also use the background
shorthand can basically only be used to specify a background color.
The ::selection
pseudo-element was drafted for CSS Selectors Level 3 but was removed before it reached the Candidate Recommendation status, and it is currently not part of any CSS module on the standards track. However, it is still implemented in most browsers, and is likely to remain so.
Examples 2h2053
The following example sets the foreground and background colors of any selected portion of a page:
::selection { background-color: #222; color: white; }
The following example sets the foreground and background colors of text highlighted in a blockquote:
blockquote::selection { background-color: #aaa; color: white; }
Browser 572e63
The ::selection
pseudo-element is ed in Chrome, Safari, Opera, and Internet Explorer 9+.
Firefox s it prefixed with the -moz-
prefix, in the form: ::-moz-selection
.
Using text-shadow
in ::selection
is only ed in Chrome, Safari, Opera, nd Firefox.