DEV Community

Cover image for Override selection style with CSS
Adam K Dean
Adam K Dean

Posted on

3

Override selection style with CSS

You may have noticed that certain designs, such as the amazing SI Digital website, have a custom style for the selection of text. When used properly, to match your designs main colour for example, this can give a really nice and polished feel.

It's really quite simple to implement as well. You can change the foreground color as well as the background color like so:

::selection { color: white; background: #5AB54A; }
::-moz-selection { color: white; background: #5AB54A; }
Enter fullscreen mode Exit fullscreen mode

Not all properties can be set using ::selection though. Properties that can be set are color, background, background-color and text-shadow. Though according to this article, background-image is ignored. Setting the background to use an image is also ignored, and it appears that opacity is also set and unable to be changed.

Still, this is a very nice feature for modern browsers, and can really add that finishing touch to your design.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

If this article connected with you, consider tapping ❤️ or leaving a brief comment to share your thoughts!

Okay