The colour of selected text can be easily changed by using the CSS | ::selection Selector. In the below code, we have used CSS ::selection on <h1> and <p> element and set its colour as yellow with green background.
Below example implements the above approach:
- How to change border-color of a canvas text using Fabric.js ?
- How to change background color of canvas-type text using Fabric.js ?
- How to change an element color based on value of the color picker value on click?
- How to change an element color based on value of the color picker value using onclick?
- How to change selected value of a drop-down list using jQuery?
- Text Animation with changing the color of the text using HTML & CSS
- How to get selected text from a drop-down list using jQuery?
- How to change SVG color ?
- How to change color of PNG image using CSS?
- How to change navigation bar color in Bootstrap ?
- How to change Hamburger Toggler color in Bootstrap ?
- How to change the background color of the active nav-item?
- Change an HTML5 input placeholder color with CSS
- How to change the font-color of disabled input using CSS ?
- How to change the placeholder text using jQuery?
- How to Change the Text of a Button using jQuery?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.