Selection in CSS | CSS ::selection

How To Change Text Selection Color

Selection in CSS ::selection is a selector of CSS, that highlighted the text, which is selected by the user.

For example, a part of a web page that is selected by the user using any device like a mouse or any pointing device.

See an image (selection CSS), also I provide the complete demo,

Selction in CSS | CSS ::selection

When you use ::selection that can change the background and foreground of the text of selected text.

CSS Syntax | ::selection

::selection {
    CSS property declarations;
}

On the below example, we change the background text color using ::selection CSS property,

::selection {
    background-color: red;
    color: white;
}

The above ::selection CSS code supported by all the browser but for Mozilla firefox, we change the code,

/* Code for Mozilla Firefox */
::-moz-selection {
  color: red;
  background: yellow;
}

How to disable text selection highlighting

Here is a code for disable text selection highlighting,

<p class="element"
 style="color:red;-moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none;" 
 unselectable="on"
 onselectstart="return false;" 
 onmousedown="return false;">
    You Can not select me
</p>

CSS ::selection Live Demo

See the Pen CSS ::selection PHPCODER.TECH by Bikash Panda (@phpcodertech) on CodePen.

Also Check:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 163

13 thoughts on “Selection in CSS | CSS ::selection

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort -

takip7.com

We are now accepting Guest Posting and creation of Backlinks
This is default text for notification bar