English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

Comprehensive CSS Attributes

CSS3 ::selection Selector

::selection CSS pseudo-element is applied to the part of the document that is highlighted by the user (such as the part selected with the mouse or other selection devices).

Complete CSS Selector Reference Manual

Online Example

Make selected text blue:

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
::selection
{
color:#0000ff;
}
::-moz-selection
{
color:#0000ff;
}
</style>
</head>
<body>
<h1>Try to select some text on this page</h1>
<p>This is some text.</p>/p>
<div>This is some text within a div element.</div>/div>
<a href="//www.oldtoolbag.com/" target="_blank">Link oldtoolbag.com!/a>
</body>
</html>
Test and see ‹/›

Definition and Usage

::selection {
  background-color: cyan;
}

::selection selector matches the part of the element that is selected or highlighted by the user.

::selection can only be applied to a few CSS properties: color, background, cursor, and outline.

Browser Compatibility

IEFirefoxOperaChromeSafari

E9+, Opera, Google Chrome and Safari support ::selection selector.

Firefox through its private property ::-moz-selection support.

Complete CSS Selector Reference Manual