::selection
::selection styles the highlighted text when a user selects it with their cursor. Only color, background-color, and text-shadow are supported.
::selection styles the highlighted text when a user selects it with their cursor. Only color, background-color, and text-shadow are supported.
/* Custom selection color */
::selection {
background-color: #007bff;
color: white;
}
/* Per-element selection */
.code-block::selection {
background-color: #0d6efd;
color: #fff;
}
/* Subtle yellow highlight */
article::selection {
background-color: #fff176;
color: #333;
}
Use a selection color that contrasts well with the text — poor contrast makes selected text hard to read.