CSS | ::selection Selector

The selection selector is used to set the CSS property to the part of document that is selected by the user (such as clicking and dragging the mouse across text). Only some CSS properties is used with ::selection selector. Supported CSS property are color, background, cursor, and outline.

Syntax:

::selection {
    // CSS Property
}

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>::selection Selector</title>
        <style>
            h1 {
                color: green;
            }
            body {
                text-align:center;
            }
              
            /* CSS property for Firefox */
            ::-moz-selection { 
                color: white;
                background: green;
            }
              
            ::selection {
                color: white;
                background: green;
            }
        </style>
    </head>
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>::selection selector</h2>
        <p>A Computer Science portal for geeks </p>
    </body>
</html>                    

chevron_right


Output:
selection

Supported Browsers: The browser supported by ::selection Selector are listed below:

  • Apple Safari 3.1
  • Google Chrome 4.0
  • Firefox 62.0 2.0-moz-
  • Opera 10.1
  • Internet Explorer 9.0


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.