Change Text Selection Color using CSS

 

Recently when visiting a website I noticed that when its text was selected it had a theme that fit his website. Normally when text is selected it is a dark blue color. Now if your website doesn’t have any blue in it, would this not look a bit out of place?

When hunting for the solution of how this was done, I was pleasantly surprised how easy it was. Just add the following CSS to your page:

::selection            { background: #A8141B; color: white; /* Safari */ }
::-moz-selection    { background: #A8141B; color: white; /* Firefox */ }

As you can see, this only works in Firefox and Safari at the moment. This may seem like nothing, but it is a subtle effect that can add some visual appeal to your website!

Highlight any text on this page to view the above CSS in action (using Safari / Firefox).

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Add to favorites
  • Design Float
  • DZone
  • email
  • FriendFeed
  • PDF
  • Propeller
  • Reddit
  • RSS
  • StumbleUpon
  • Twitter

Related posts:

  1. CSS Rounded Corners
  2. Snazzy CSS Double Border Effect
  3. Animate Text with jQuery Easing (screencast)
  4. CSS/JavaScript Hover Menu (screencast)
  5. Photoshop Slicing & CSS Coding


Written by Brenley Dueck

 

7 Responses to “Change Text Selection Color using CSS”

  1. Hugo Says:

    December 15th, 2008 at 5:56 am

    Works well in Google Chrome 0.4 – 1.0 and FLock 2.0. Maxthon and IE (as expected) did not work.
    Nice effect! Adds that touch of detail and what I like to call ‘distinction’ to a site. Thanks for sharing!

  2. Cambiar el color del texto seleccionado en el navegador con CSS « Webmaster Libre Says:

    December 19th, 2008 at 8:43 am

    [...] Vía Brenezl [...]

  3. Hashim Says:

    December 21st, 2008 at 11:49 pm

    I need to know more about CSS

  4. Jake Says:

    January 1st, 2009 at 4:11 pm

    Thanks for this, I was afraid I would have to go into complicated javascripts to get this result.

  5. Cambiar el color del texto seleccionado en el navegador con CSS | Mantis Technology Solutions Blog Says:

    January 10th, 2009 at 6:50 pm

    [...] Vía Brenezl [...]

  6. Joren Rapini Says:

    January 19th, 2009 at 10:26 am

    Nice man! I just saw this effect on css-tricks, googled it and yours was the first site that came up.

  7. Aksel Says:

    May 18th, 2009 at 2:45 pm

    Testing your CSS trick I found out that you have one of the most broken appearance in IE 6 that I have seen lately.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
connect with me!