CSS ::selection pseudo-element

Definition and usage

CSS ::selection Pseudo-elements are used to set the style of the selected text part of the user.

Note:The following properties can be used with ::selection Used together:

  • color
  • background-color
  • text-decoration
  • text-shadow

Example

Set the text color to red and the background to yellow for the selected text of the user:

::selection {
  color: red;
  background: yellow;
}

Try it yourself

CSS syntax

::selection {
  css declarations;
}

Technical details

Version: CSS3

Browser support

The numbers in the table specify the first browser version that fully supports this pseudo-element.

Chrome Edge Firefox Safari Opera
4 12 62 1.1 9.5