Code Snippets

Change Text Selection Color With CSS

Maan
Jan 4, 2014
1 min read
93 words

Changing the text selection color is always a nice touch, it shows that you’re paying attention to the finer details of the site.
Today in this snippet we share a quick tip that will allow you to achieve some different looks for your selected text.

[css]
/* Mozilla based browsers */
::-moz-selection {
background-color: #FF68B0;
color: #FFF;
}
/* Works in Safari */
::selection {
background-color: #FF68B0;
color: #FFF;
}
/* Works in Opera */
::-o-selection {
background-color: #FF68B0;
color: #FFF;
}
::-ms-selection {
background-color: #FF68B0;
color: #FFF;
}
/* Works in Internet Explorer */
::-webkit-selection {
background-color: #FF68B0;
color: #FFF;
}
[/css]

View Source →

Maan

Author

Maan is a Lead Frontend Engineer and Creative Director with 10+ years of industry experience blending UI/UX design with React-based development. A multifaceted practitioner, he has spent a decade turning abstract inspiration into deployed, scalable reality. Maan’s expertise lies in high-fidelity prototyping and component architecture, which he shares through insightful technical writing with the next generation of developers. His unique approach ensures that pixels not only meet passion but also rigorous performance standards.

View all posts

Continue reading

You might also like

One response to “Change Text Selection Color With CSS”

  1. Hi!

    Thanks for sharing your discoveries.

    I can complete it a bit.
    There is only the “-moz-” vendor, others do not exist: http://caniuse.com/#feat=css-selection

    The folowing lines are good enough:
    /* Mozilla based browsers */
    ::-moz-selection {
    background-color: #FF68B0;
    color: #FFF;
    }
    /* Works in IE, chrome, safari & opera */
    ::selection {
    background-color: #FF68B0;
    color: #FFF;
    }

    Cheers,
    Thomas.

Leave a Reply

Your email address will not be published. Required fields are marked *

Menu