Files
30-seconds-of-code/snippets/custom-text-selection.md
Angelos Chalaris 7e69307433 Update tags, expertise and descriptions across
Fix anything that was a bit out of place
2020-03-05 22:52:51 +02:00

33 lines
759 B
Markdown

---
title: Custom text selection
tags: visual,beginner
---
Changes the styling of text selection.
```html
<p class="custom-text-selection">Select some of this text.</p>
```
```css
::selection {
background: aquamarine;
color: black;
}
.custom-text-selection::selection {
background: deeppink;
color: white;
}
```
#### Explanation
- `::selection` defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.
#### Browser support
<span class="snippet__support-note">⚠️ Requires prefixes for full support and is not actually in any specification.</span>
- https://caniuse.com/#feat=css-selection