::selection
W3C CSS Snapshot 2026
Style the text a user selects.
On this page
Syntax and values
| Value or syntax | What it does |
|---|---|
p::selection | Styles a selected part of the paragraph, using supported properties such as color and background-color. |
Try the example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>::selection</title>
<style>
p::selection { background: teal; color: white; }
</style>
</head>
<body>
<p class="notice">Registration opens Monday.</p>
<p id="location">Meet in Room 2.</p>
<h2>Workshop</h2>
</body>
</html>
What to expect Select part of a paragraph to reveal the teal highlight.