::selection - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:selection

Description

The ::selection selector selects the selected part within an element.

::selection selector can only apply the following attribute:

  • color
  • background
  • cursor
  • outline.

Example

Change the selected text color

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
::-moz-selection { /* Code for Firefox */
    color: red;
    background: yellow;
}

::selection {<!--from w  w w. j av a 2 s  . co  m-->
    color: red;
    background: yellow;
}
</style>
</head>
<body>

<h1>Select some text on this page:</h1>

<p>This is a paragraph.</p>
<div>This is some text in a div element.</div>

</body>
</html>

Related Tutorials