Text Selection Color and Background

Posted By : Deepak Insa | 29-Jun-2015

To change default color and background setting of text selection, we have to apply CSS3’s properties.

These CSS Properties are:-

/* Mozilla based browsers */
::-moz-selection {
       background-color: #ccc;
       color: #00f;
}

/* Works in Safari */
::selection {
       background-color: #ccc;
       color: #00f;
} 

 

For Example I want to change selection text color to RED and background to BLUE then I have to apply these properties:- 

HTML

<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

 

CSS

p::-moz-selection {
       background-color: #00f;
       color: #f00;
}
p::selection {
       background-color: #00f;
       color: #f00;
} 

 

Then the result will be show like this:-

 

About Author

Author Image
Deepak Insa

Deepak is an experienced UI developer with experience and capabilities to build compelling UIs for Web and Mobile Applications.

Request for Proposal

Name is required

Comment is required

Sending message..