Skip to content
Related Articles
Open in App
Not now

Related Articles

CSS | ::selection Selector

Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 23 Aug, 2022
Improve Article
Save Article
Like Article

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: 

html




<!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>                   

Output:

 selection 

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

  • Apple Safari 1.1 and above
  • Google Chrome 1.0 and above
  • Edge 12.0 and above
  • Firefox 62.0 and above
  • Opera 9.5 and above

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!