::selection

Brand the highlight: how ::selection swaps the OS-blue selection for an accent color, and the narrow set of properties it actually honors.

By Kacper Szarkiewicz

Drag-select text on almost any site and you get the same OS-blue highlight. It's one of the easiest places to plant a brand color - a single CSS rule, no markup change, no JavaScript.

::selection {
  background-color: #17c3fa;
  color: white;
}

Drag across both columns

Without ::selection

Drag across this paragraph to see how the highlight is painted.

With ::selection

Drag across this paragraph to see how the highlight is painted.

The catch is that ::selection only honors a narrow set of properties: color, background-color, text-decoration, text-shadow, and the SVG fill / stroke pair. Anything else - background-image, padding, font-size, transitions - is silently ignored. The browser paints a flat overlay on top of the real text, it doesn't render a separate element you can fully style.

Treat it as a brand-color slot, not a full style hook, and check contrast on the way out. The new color sits over arbitrary content, so a soft accent that looks right on the hero can quietly fail WCAG against body copy further down the page.

Newsletter

Stay updated with my latest articles and projects. No spam, no nonsense.