The ::selection
pseudo element is available in Chrome's dev tools as the last style in the styles pane - almost as if it were the least specific style. To view it, make sure you have it defined in your stylesheet, then select some text and inspect one of the selected words/areas.
As was mentioned by @Sampson, you can also add ::selection
styles using just ::selection
or a more specific selector, like p::selection
or span::selection
. Keep in mind, however, that according to the spec, you can only affect the color
, background-color
, cursor
, outline
, text-decoration
, text-emphasis-color
and text-shadow
with the ::selection
pseudo element.
Another consideration when using the ::selection
pseudo is that you may be affecting accessibility by creating selections that lack in contrast. You also may be affecting visibility of links. In such cases, you can test your contrast using a contrast examiner tool and you can create more specific ::selection
styles for links - something like:
span::selection {
background-color: #b3d8fd;
}
a.footnote span::selection {
color: #920000;
}
::selection
rule in the stylesheet. – Laicize