Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get default selection color?

Tags:

css

I can change the CSS selection color, but how can I get the browser/OS default selection so that I can use it elsewhere?

e.g. on Ubuntu+Chrome text is highlighted in orange.

enter image description here

I want to apply this same style to an <li> when I hover over it with my mouse.

like image 722
mpen Avatar asked Jun 23 '26 21:06

mpen


1 Answers

In the CSS2 specs some color keywords are defined. They should still work just fine but might not necessarily reflect how selected text look like:

.selected {
  background: Highlight;
  color: HighlightText;
}
<p>Lorem ipsum with some <span class="selected">selected text</span></p>

//edit: The previous answer stated, that those keywords are deprecated. As @vpzomtrrfrt pointed out in the comments below, they are not.

like image 176
lumio Avatar answered Jun 25 '26 10:06

lumio