CSS text selection color change

Here’s how to change the text selection color using CSS.

1. Suppose this is the text you want to change the color on selection.

<h1>Select this text</h1>

2. You can either target the single element, h1 in this case, h1::selection. Or apply it to all the elements like below.

::selection {
  background-color: teal;
  color: #fff;
}

Output:

Select this text

Recently added:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x