Announcement

Collapse
No announcement yet.

Creating a custom text selection / highlight colour in CSS?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating a custom text selection / highlight colour in CSS?

    I have noticed many websites nowadays have custom text highlight colours (including the eUKhost website). I'd really like to be able to do this on my own website. Forgive me if this is a rookie question, but can someone tell me how I can do this? Is there some CSS code I need to use?

    Thanks.

  • #2
    Re: Creating a custom text selection / highlight colour in CSS?

    This is possible using the ::selection pseudo-element:

    Code:
    ::selection
    {
         /* code here */
    }
    
    ::-moz-selection
    {
         /* code here */
    }
    Unfortunately, this pseudo-element is unofficial and is not recognised in any official W3C spec. Thankfully, there is relatively wide browser support nowadays, but because it is unofficial, browsers may drop support for it in the future.

    ::selection is supported in IE 9 and above, Chrome 4 and above, Safari 3.1 and above and Opera 9.6 and above. As ::selection is 'unofficial', Firefox only supports it through its own pseudo-element, ::moz-selection.

    Comment


    • #3
      Re: Creating a custom text selection / highlight colour in CSS?

      even we can do it in html with css attributes....
      http://www.rgbdzine.com

      Comment

      Working...
      X