Dev Helpers

CSS / Adaptive controls

Selection background swatch

Dev Helpers · February 10, 2026

Selection styling needs foreground and background colours that remain readable as a pair. Test actual selected text rather than an isolated colour chip.

Worked example

<style>
  .demo::selection {
    background: #fde68a;
    color: #111827;
  }
</style>
<p class="demo">Select this sentence to see the proof colour.</p>

Implementation notes

A browser may limit which properties apply to the selection pseudo-element. Prefer a simple foreground-and-background pairing over relying on effects.

Try it yourself

Select across a link and its surrounding paragraph.

Open the CSS example →

Editorial date February 10, 2026 · Published December 6, 2026

Related articles

Fluid width with a maximum

A fluid container needs a small-screen width and a large-screen maximum. Outer gutters should remain visible at both extremes.

Square aspect ratio

A square ratio reserves equal sides even before media loads. Fit rules decide whether rectangular content is cropped or letterboxed.