Read more

CSS: Change text selection color

Arne Hartherz
February 20, 2012Software engineer at makandra GmbH

You can change the color for text selection via CSS, using the ::selection and ::-moz-selection pseudo-elements.

Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

Adding this to your Sass will make all text selections use a red background:

::selection
  background-color: #f00

::-moz-selection
  background-color: #f00

Unfortunately, those can't be combined into "::selection, ::-moz-selection". Doing so will have no effect.

Posted by Arne Hartherz to makandra dev (2012-02-20 11:07)