When someone drags over text to copy it, the browser paints it in the system highlight color. ::selection lets you pick a color that matches the site.
::selection {
background-color: #ffe08a;
color: #1f2328;
}
pre ::selection {
background-color: #264f78;
color: #ffffff;
}
The first rule applies to all text on the page. The second one gives code blocks their own darker highlight, because a yellow on a dark code theme is hard to read. Note the space in pre ::selection: that targets selected text inside the block.
Only a small set of properties works here: color, background-color, text-decoration and its parts, text-shadow and a few stroke properties. A background-image or padding is ignored.
I’d always pick a pair with enough contrast. People select text to read it closely or to copy it, and a pale highlight with pale text defeats the purpose.
Desktop browsers all support it. According to MDN, Safari on iPhone and iPad ignores it and keeps the system color, so do not rely on it to make anything readable there.
Further reading: MDN: ::selection